作者: 竹叶君子 时间: 2015-3-1 13:27
class Test1
{
public static void main(String[] args)
{
int[] arr={1,2,3,4,5,6,7,8,9,12};
int key=8;
int n= halfSearch(arr,key);
int m=halfSearch_1(arr,key);
System.out.println("毕向东老师的代码结果"+n);
System.out.println("减1后的结果"+m);
}
public static int halfSearch(int[] arr,int key)
{
int min,max,mid;
min = 0;
max = arr.length-1;
mid = (max+min)/2;
while(arr[mid]!=key)
{
if(key>arr[mid])
min = mid + 1;
else if(key<arr[mid])
max = mid - 1;