C语言 数据结构 实验五
8610 - 顺序查找
#include "malloc.h"
#include "stdio.h"
#include "stdlib.h"
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
}SSTable;
void Create_Seq(SSTable &ST, int n)
{
int i, temp;
ST.elem = (ElemType *)malloc(sizeof(ElemType) * (n+1));
if(!ST.elem)
{
printf("EEROR\n");
exit(0);
}
for(i = 1; i <= n; i++)
{
scanf("%d", &temp);
*(ST.elem+i) = temp;
}
ST.length = n;
}
int Search_Seq(SSTable &ST, ElemType key)
{
int i;
for(i = ST.length; key != ST.elem[i] && 0 != i; i--);
return i;
}
int main()
{
SSTable ST;
int loc, key;
int n;
scanf("%d", &n);
Create_Seq(ST, n)