标题: 二分法查找 [打印本页] 作者: 以梦为马123 时间: 2015-8-26 00:44 标题: 二分法查找 //二分法查找数组toBinary
public static int search(int[] array,int key)
{
int min = 0;
int max = array.length-1;
int mid = (min + max)/2;
while(key != array[mid])
{
if (key > array[mid])
{
min = mid+1;
}else
{
max = mid-1;
}
mid = (min + max)/2;
if (min > max)
{
return -1;
}
}
return mid;