二分查找

来源:互联网 发布:msa是什么软件啊 编辑:程序博客网 时间:2024/05/19 02:05
int bsearchWithoutRecursion(int array[], int low, int high, int target)
{
while(low <= high)
{
int mid = (low + high)/2;
if (array[mid] > target)
high = mid - 1;
else if (array[mid] < target)
low = mid + 1;
else //find the target
return mid;
}
//the array does not contain the target
return -1;
}
0 0
原创粉丝点击