STL——Binary search(二分查找)
程序员文章站
2024-03-17 18:59:04
...
转自:http://www.cnblogs.com/wkfvawl/p/9475939.html
二分算法模板:
while (left <= right) {
int mid = (left + right) / 2;
if (array[mid] == key) {
return mid;
}
else if (array[mid] < key) {
left = mid + 1;
}
else {
right = mid - 1;
}
}