java 二分法查找
程序员文章站
2022-03-13 12:50:18
...
public static int halfSearch(int a[],int key){
int low = 0, hight = a.length - 1;
while(low <= hight){
int mid = (low + hight)/2;
if (a[mid] == key)
return mid;
else if (a[mid] < key)
low = mid + 1;
else
hight = mid + 1;
}
return -1;
}