#include<stdio.h>
#include<stdlib.h>
typedef int KeyType;
typedef struct{
KeyType key;
}ElemType;
typedef struct{
ElemType *elem;
int length;
}SSTable;
enum status{
error,ok
};
status EQ(KeyType key,KeyType y)
{
if(key==y)
return ok;
else
return error;
}
status LT(KeyType key,KeyType y)
{
if(key<y)
return ok;
else
return error;
}
int searchBin(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 main()
{
SSTable ST;
ST.elem[0].key=5;
ST.elem[1].key=13;
ST.elem[2].key=19;
ST.elem[3].key=21;
ST.elem[4].key=37;
ST.elem[5].key=56;
ST.elem[6].key=64;
ST.elem[7].key=75;
ST.elem[8].key=80;
ST.elem[9].key=88;
ST.elem[10].key=92;
int m=searchBin(ST,13);
printf("m=%d",m);
}
这个程序运行时出现异常,亲能帮我解决一下吗?出现一个警告是ST违背初始化