代码实现
//@todo 今晚添加详细解释。
function bSearch(arr:number[], value: number):number {
let low = 0;
let high = arr.length - 1;
while(low <= high) {
let mid = ~~((low + high) / 2);
let midValue = arr[mid];
if (arr[mid] === value) {
return mid;
} else if ( midValue > value){
high = mid - 1;
} else {
low = mid + 1;
}
}
return -1;
}