您的位置:首页 > 其它

STL:map中的lower_bound和upper_bound

2015-11-09 23:00 295 查看
今天在做leetcode的Longest Increasing Subsequence题目时,需要用到二分查找,于是翻看了《STL源码剖析》这本书,发现map里面有lower_bound和upper_bound这两个函数。用法如下:

map<int,int> m;

int x=10;

map<int,int>::iterator ite;

ite=m.lower_bound(x);//返回比第一个大于或等于x的值的位置
,当m为空时,返回m.begin()

ite=m.upper_bound(x);//返回比最后一个大于或等于x的值的位置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: