// 给的一个数组----.前提:--->数组必须是有序的
int[] arr = {1, 3, 5, 7, 9, 11, 13};
int index = binarySearch( arr, 8, 0, arr.length -1 );
System.out.println( index );
}
public static int binarySearch(int[] arr, int item, int low, int higt) {
if (low > higt) {//递归结束条件
return -1;
}
System.out.println("------" );
int mid = (low + higt) /2;
int guess = arr[mid];//永远瞎猜,猜中间数
if (guess > item) {
return binarySearch( arr, item, low, mid -1 );
}else if (guess == item) {
return mid;
}else {
return binarySearch( arr, item, mid +1, higt );
}
}