public static void main(String[] args) {
int[] array = {1,3,5,7,9,10,12,13,14};
int result = binarySearchController(array,0);
System.out.println("查找结果是:"+result);
}
private static int binarySearchController(int[] array, int i) {
return binarySearch(array,i,0,array.length-1);
}
private static int binarySearch(int[] array, int i , int low ,int high) {
if(low>=high){
return -100;
}
if(array[low]==i){
return array[low];
}else if(array[high]==i){
return array[high];
}
int mid = (low+high)/2;
if(array[mid]==i){
return array[mid];
}else if(array[mid]>i){
return binarySearch(array,i,low+1,mid);
}else{
return binarySearch(array,i,mid,high-1);
}
}