#define MaxSize 50
typedef strcut{
ElemType data[MaxSize];
int length;
}Sqlist;
bool binary_search(Sqlist L,ElemType k){
int low=0,high=L.length-1,mid;
while(low<=high){
mid=(low+high)/2;
if(k==L.data[mid]) //插入值与中间值相同则返回真
return true;
else if(k<L.data[mid])
high=mid-1;
else
low=mid+1;
}
return false; //查找结束也没找到返回假
}
【7 查找】顺序表折半查找。
最新推荐文章于 2024-05-30 16:17:47 发布