数据结构
实验十一:(查找实验,设计性)
代码
关键词查询1.0
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 100
#define OK 1;
#define OVERFLOW -1;
typedef int Status;
typedef int KeyType;
typedef int InfoType;
typedef struct{
KeyType key;
InfoType otherinfo;
}ElemType;
typedef struct{
ElemType *elem;
int length;
}SSTable;
Status Creat_SSTable(SSTable &ST)
{
ST.elem = (ElemType *)malloc(MAXSIZE*sizeof(ElemType));
if (!ST.elem)
return OVERFLOW;
ST.length=0;
return OK;
}
int Search_Seq(SSTable ST, KeyType key)
{
int i;
ST.elem[0].key = key;
for(i=ST.length; ST.elem[i].key!= key; i--);
return i;
}
int Search_Bin(SSTable ST, KeyType key)
{
int low=1;
int high=ST.length;
while(low<=high)
{
int mid=(low+high)/2;
if(key==ST.elem[mid].key)
return mid;
else if(key<ST.elem[mid].key)
high=mid-1;
else
low=mid+1;
}
return 0;
}
void Sort_Select(SSTable &ST)
{
for(