Position BinarySearch(List L,ElementType x)
{
int low=1,high=L->Last;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(L->Data[mid]==x)
return mid;
if(x<L->Data[mid])
high=mid-1;
if(x>L->Data[mid])
low=mid+1;
}
if(low>high)
return NotFound;
}
习题1.8 二分查找 (20分)
最新推荐文章于 2022-08-07 07:03:05 发布