本帖最后由 初艳春 于 2012-11-25 10:29 编辑
class Test
{
public static void main(String[] args)
{
int[] a = {3,4,6,7,11,34,56};
int index1=halfSearch(a,3);
System.out.println("index1= "+index1);
}
public static int halfSearch(int[] a,int key)
{
int min,max,mid;
min=0;
max=a.length-1;
mid=(min+max)/2;
while(a[mid]!=key)
{
if(key>mid)
min=mid+1;
else if(key<mid)
max=mid-1;
if(min>max)
return -1;
mid=(max+min)/2;
}
return mid;
}
}
怎么没有运行结果啊?
|