此算法依赖于排序算法:快速排序
/**
* 二分查找,要求输入数列有序方可查询。常用于变动比较小的数据,且有序。时间复杂度可以表示O()=O(logN)
*/
static class BinaryChop {
public int search(int[] sources, int search, int start, int end) {
//int half = (end + start) / 2;
int half = start + (end - start) / 2;
return (start > end) ? (-1) : ((sources[half] == search) ? (half) : ((sources[half] < search) ? (search(sources, search, half + 1, end)) : (search(sources, search, start, half - 1))));
}
}