【文件属性】:
文件名称:顺序和折半查找
文件大小:1KB
文件格式:DOC
更新时间:2015-01-07 08:15:56
顺序和折半查找
顺序和折半查找
已验证
好啊
!#include
typedef struct{
int elem[50] ;
int length;
}SSTable;
int Search_Seq(SSTable ST,int key)
{
int i,x=0;
ST.elem[0]=key;
for(i=ST.length;ST.elem[i]!=key;--i)x++;
printf("进行了%d次查询!\n",x);
return i;
}//Search_Seq
int Search_Bin(SSTable ST,int key)
{
int low,high,mid;
int con=0;
low=1;
high=ST.length;
while(low<=high)
{
con++;
mid=(low+high)/2;
if(ST.elem[mid]==key)
{
printf("进行了%d查询!\n",con);
return mid;
}
else if(ST.elem[mid]>key)
high=mid-1;
else low=mid+1;
}
return 0;
}//Search_Bin