/**
* @Author Gao Xiaozhuang
* @Date 2020/7/27 13:43
* @WARN 要写注释
* @Version 1.0
* @Description折半查找
*/
public class BinSearch {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 16, 17, 19};
int low = 0;
int high = arr.length - 1;
int desc = 13;
while (true) {
int middle = (low + high) / 2;
if (desc == arr[middle]) {
System.out.println(middle);
break;
} else if (desc < arr[middle]) {
high = middle - 1;
} else {
low = middle + 1;
}
}
}
}