/*
* 递归之二分查找
* 二分查找就是在一个有序的数据中,先找到中间索引,取到中间索引的元素跟需要查找的元素对比,如果刚好相等,则返回该元素
* 如果中间索引的元素大于需要查找的元素,然后再取出开始的节点到中间节点的元素的中间索引的元素进行对比。以次类推
* 代码示例如下:
*/
public class RecursiveDichotomy {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int desc = Integer.valueOf(sc.next());
int[] arr = { 1, 2, 3, 5, 6, 7, 8, 9, 15, 16, 18, 19, 25, 27, 29, 34, 36, 38, 40, 59, 67, 89, 95, 100 };
int index = dichotomySearch(0,arr.length-1, arr, desc);
if(index < 0){
System.out.print("数组里面没有您要找的目标数:"+desc);
}else{
System.out.print("您要查找的目标数:"+ desc +"的索引为:"+index);
}
}
private static int dichotomySearch(int start, int e