lower_bound 和 upper_bound
Return iterator to lower bound
Returns an iterator pointing to the first element in the range [first,last)
which does not compare less than val.
Return iterator to upper bound
Returns an iterator pointing to the first element in the range [first,last)
which compares greater than val.
// lower_bound/upper_bound example
#include <iostream> // std::cout
#include <algorithm> // std::lower_bound, std::upper_bound, std::sort
#include <vector> // std::vector int main () {
int myints[] = {,,,,,,,};
std::vector<int> v(myints,myints+); // 10 20 30 30 20 10 10 20 std::sort (v.begin(), v.end()); // 10 10 10 20 20 20 30 30 std::vector<int>::iterator low,up;
low=std::lower_bound (v.begin(), v.end(), ); // ^
up= std::upper_bound (v.begin(), v.end(), ); // ^ std::cout << "lower_bound at position " << (low- v.begin()) << '\n';
std::cout << "upper_bound at position " << (up - v.begin()) << '\n'; return ;
}
Output:
lower_bound at position 3 |
lower_bound 和 upper_bound的更多相关文章
- STL源码学习----lower_bound和upper_bound算法
转自:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html 先贴一下自己的二分代码: #include <cstdio&g ...
- [STL] lower_bound和upper_bound
STL中的每个算法都非常精妙, ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一 ...
- vector的插入、lower_bound、upper_bound、equal_range实例
对于这几个函数的一些实例以便于理解: #include <cstdlib> #include <cstdio> #include <cstring> #includ ...
- STL中的lower_bound和upper_bound的理解
STL迭代器表述范围的时候,习惯用[a, b),所以lower_bound表示的是第一个不小于给定元素的位置 upper_bound表示的是第一个大于给定元素的位置. 譬如,值val在容器内的时候,从 ...
- STL 源码分析《5》---- lower_bound and upper_bound 详解
在 STL 库中,关于二分搜索实现了4个函数. bool binary_search (ForwardIterator beg, ForwardIterator end, const T& v ...
- lower_bound和upper_bound算法
参考:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html ForwardIter lower_bound(ForwardIte ...
- STL源码学习----lower_bound和upper_bound算法[转]
STL中的每个算法都非常精妙,接下来的几天我想集中学习一下STL中的算法. ForwardIter lower_bound(ForwardIter first, ForwardIter last,co ...
- [转] STL源码学习----lower_bound和upper_bound算法
http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html PS: lower_bound of value 就是最后一个 < ...
- STL algorithm算法lower_bound和upper_bound(31)
lower_bound原型: function template <algorithm> std::lower_bound default (1) template <class F ...
随机推荐
- fastjson生成和解析json数据
本文讲解2点: 1. fastjson生成和解析json数据 (举例:4种常用类型:JavaBean,List<JavaBean>,List<String>,List<M ...
- 解决“未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker”错误
转自:http://blog.csdn.net/andrew_wx/article/details/6947317 解决办法: ALTER DATABASE 数据库名称 SET NEW_BROKER ...
- ifconfig报错:SIOCSIFFLAGS: Operation not permitted
# insmod mt7601Usta.ko rtusb init rt2870 --->usbcore: registered new interface driver rt2870 # iw ...
- vs 引用sqlite的问题
错误 4 未能找到类型或命名空间名称“SQLiteCommand”(是否缺少 using 指令或程序集引用?) D:\01学习\SQLite\HBZCSCXT_Mobile\SqlLiteHelper ...
- Linux下生成patch和打patch
转自:http://blog.csdn.net/dl0914791011/article/details/17299103 通过diff工具生成补丁, patch工具打上补丁. 在使用diff之前, ...
- 【转】T-SQL 教程
USE [test] GO /****** Object: StoredProcedure [dbo].[PageIndex] Script Date: 12/07/2011 10:26:36 *** ...
- J2EE学习中一些值得研究的开源项(转)
这篇文章写在我研究J2SE.J2EE近三年后.前3年我研究了J2SE的Swing.Applet.Net.RMI.Collections. IO.JNI……研究了J2EE的JDBC.Sevlet.JSP ...
- could not open extension control file "/usr/share/postgresql/9.1/extension/plpythonu.control": No such file or directory
在使用createlang 安装plpythonu的时候出现如下错误:could not open extension control file "/usr/share/postgresql ...
- 1.html5 学习要求,Html 5发展历程
以下是我在学习html5,项目中用到的关于html5的总结和心得. 1.学习要求 Html4.01,xhtml Css2 Javascript 耐心,动手,毅力. 2.Html 发展历程 Html1. ...
- Oracle远程数据库一直连接不上的原因:多了个空格