标题: 学习 [打印本页] 作者: 暴雨 时间: 2016-6-12 17:06 标题: 学习 private static int binarySearch0(char[] a, int fromIndex, int toIndex,
char key) {
int low = fromIndex;
int high = toIndex - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
char midVal = a[mid];
if (midVal < key)
low = mid + 1;
else if (midVal > key)
high = mid - 1;
else
return mid; // key found
}
return -(low + 1); // key not found.
}