c++ 中 lower_bound 和 upper_bound 的用法
lower_bound 和 upper_bound 都是利用二分查找的方法在一个排好序的数组中进行查找的
在从小到大的排序数组中:
lower_bound(begin, end, num)
从数组的 begin 位置到 end-1 位置二分查找第一个大于或等于 num 的数字,找到返回该数字的地址,不存在则返回 end。upper_bound(begin, end, num)
从数组的 begin 位置到 end-1 位置二分查找第一个大于 num 的数字,找到返回该数字的地址,不存在则返回 end。
重载 lower_bound 和 upper_bound 。在一个从大到小的数组中:
1 | int main() { |