package Day52;
/**
* @Author Zhongger
* @Description 分治递归查找
* @Date 2020.3.26
*/
public class BinarySearch {
public static void main(String[] args) {
BinarySearch search = new BinarySearch();
int[] arr={1,2,3,4,5,6,7,8,9,10};
System.out.println(search.binarySearch(0, arr, 0, arr.length - 1));
}
public int binarySearch(int value,int[] arr,int left,int right){
if (left>right){
return -1;
}
int mid=(left+right)/2;
if (arr[mid]==value){
return mid;
}else if (arr[mid]<value){
return binarySearch(value,arr,mid+1,right);
}else {
return binarySearch(value,arr,left,mid-1);
}
}
}