Java 二分叉查找
Integer[] list = new Integer[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int start = 2;
int end =9;
int low = 0;
int hight = list.length - 1;
int index = 0;
while (low < hight) {
index = (hight+low) % 2 == 0 ? (hight+low) / 2 : (hight+low + 1) / 2;
if (list[index] < end) hight = index - 1;
else if (list[index] > end) low = index + 1;
else {
System.out.println(list[index]);
break;
}
}
for (int i = index + 1; i < list.length; i++) {
if (list[i] < start) break;
System.out.println(list[i]);
}