int search(int arr[],int n,int key)
{
int low = 0,high = n-1;
int mid,count=0;
while(low<=high)
{
mid = (low+high)/2;
if(arr[mid] == key)
return mid;
if(arr[mid]<key)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
上面代码段简单说明了二分法的做法:其中,arr[]是数组,n 是 数组长度,key是要找的值。
https://www.cnblogs.com/wanglog/p/6650695.html
参考