int BinarySearch(int *list, const int num, const int n)
{
int low, mid, high;
low=0;high=n-1;
while (low < high)
{
mid = (low + high) / 2;
if (list[mid] == num)
{
return mid;
}
else if (list[mid]>num)
{
high = mid - 1;
}
else if (list[mid<num])
{
low = mid;
}
}
}
算法:二分查找(折半查找)
最新推荐文章于 2022-07-10 19:39:16 发布