lower_bound
C++函数
lower_bound是C++标准模板库(
STL
)中的函数,定义于<
algorithm
>头文件中。该函数在有序序列。
C++ STL
函数原型
第一个版本(default):
第二个版本(custom):
函数介绍
例如,有如下序列:
a[i]={12,15,17,19,20,22,23,26,29,35,40,51};
用值21调用lower_bound(),返回一个指向22的iterator。用值22调用lower_bound(),也返回一个指向22的iterator。第一个版本使用底层 < (小于)
操作符
,第二个版本根据comp进行排序和比较。
注意事项
调用lower_bound之前必须确定序列为有序序列,否则调用出错。第一个版本排序根据底层的 <(小于)操作符,第二个版本根据comp进行排序。
举例
第一个版本
输出:
Before nums is: -242 -1 0 5 8 8 11
After, nums is: -242 -1 0 5 7 8 8 11
第二个版本
compareByTwoKey为compareByThreeKey。
参考资料
std::lower_bound
.cplusplus.com.
lower_bound (STL Samples)
.微软网站.2013-03-15
lower_bound
.微软网站.2013-03-27
最新修订时间:2025-12-23 09:16
条目作者
小编
资深百科编辑
目录
概述
C++ STL
参考资料
Copyright©2024
闽ICP备2024072939号-1