int BinSearch(int[] arr,int k)
{
if(arr == null || arr.length ==0)
throw new RuntimeException();
int low,high,low;
low=0;
high=arr.length;
while(low<=high)
{
mid=(low+high)/2;
if(k<a[mid])
high=mid-1;
else if(k>a[mid])
low=mid+1;
else
return mid;
}
return -(low+1);
}
二分查找
最新推荐文章于 2021-07-13 11:25:16 发布