二分法查找
适用于数组已经从大到小排序
public static int binarySearch(int[] data, int key) {
int begin = 0;
int end = data.length - 1;
int mid;
while (begin <= end) {
mid = (begin + end) / 2;
if (data[mid] == key) {
return mid;
} else if (data[mid] < key) {
begin = mid + 1;
} else {
end = mid - 1;
}
}
return -1;
}