实现代码:
Array.prototype.binary_search = function(low, high, key) {
var mid = parseInt((high + low) / 2),
low = low,
high = high,
key = key;
if(low > high)
return -1;
else {
if(key == this[mid])
return mid;
else if(key > this[mid])
this.binary_search(mid+1, high, key);
else
this.binary_search(low, mid-1, key);
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
人生最曼妙的风景,竟是内心的淡定与从容!