lower_bound/upper_bound example

http://www.cplusplus.com/reference/algorithm/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
 
 // 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 ;
}

lower_bound/upper_bound example

上一篇:[转]SecureCRT使用配置详细图文教程


下一篇:[知识库分享系列] 四、ASP.NET MVC and Winform