upper_bound()返回值
来源:互联网 发布:c语言数字字符是什么 编辑:程序博客网 时间:2024/05/18 17:56
函数upper_bound()返回的在前闭后开区间查找的关键字的上界,如一个数组number序列1,2,2,4.upper_bound(2)后,返回的位置是3(下标)也就是4所在的位置,同样,如果插入元素大于数组中全部元素,返回的是last。(注意:此时数组下标越界!!)
返回查找元素的最后一个可安插位置,也就是“元素值>查找值”的第一个元素的位置
本文出处
测试代码如下:
- #include <iostream>
- #include <algorithm>
- #include <functional>
- #include <vector>
- using namespace std;
- void main()
- {
- const int VECTOR_SIZE = 8 ;
- // Define a template class vector of int
- typedef vector<int, allocator<int> > IntVector ;
- //Define an iterator for template class vector of strings
- typedef IntVector::iterator IntVectorIt ;
- IntVector Numbers(VECTOR_SIZE) ;
- IntVectorIt start, end, it, location, location1;
- // Initialize vector Numbers
- Numbers[0] = 4 ;
- Numbers[1] = 10;
- Numbers[2] = 10 ;
- Numbers[3] = 30 ;
- Numbers[4] = 69 ;
- Numbers[5] = 70 ;
- Numbers[6] = 96 ;
- Numbers[7] = 100;
- start = Numbers.begin() ; // location of first
- // element of Numbers
- end = Numbers.end() ; // one past the location
- // last element of Numbers
- // print content of Numbers
- cout << "Numbers { " ;
- for(it = start; it != end; it++)
- cout << *it << " " ;
- cout << " }\n" << endl ;
- //return the last location at which 10 can be inserted
- // in Numbers
- location = lower_bound(start, end, 9) ;
- location1 = upper_bound(start, end, 10) ;
- cout << "Element 10 can be inserted at index "
- << location - start<< endl ;
- cout << "Element 10 can be inserted at index "
- << location1 - start<< endl ;
- }
0 0
- upper_bound()返回值
- upper_bound()返回值
- upper_bound()返回值
- lower_bound()和upper_bound()返回值
- upper_bound()返回值 lower_bound()返回值
- lower_bound()返回值 & upper_bound()返回值
- equal_range()、lower_bound() 和 upper_bound()返回值
- STL中lower_bound()、 upper_bound()的返回值
- upper_bound 和lower_bound 的返回值问题
- lower_bound 与 upper_bound 返回值及用法
- lower_bound and upper_bound 返回
- upper_bound
- lower_bound和upper_bound,原来都是求刚好大于的值
- lower_bound()、upper_bound()
- lower_bound upper_bound
- lower_bound() + upper_bound()
- std::upper_bound
- lower_bound,upper_bound
- 汉澳sinox2013安装详细图解
- 2013.03.16 ie8 不支持str.trim()的写法
- 不容易系列之(3)—— LELE的RPG难题 2045
- 字符串中最长的数字串
- 素数环
- upper_bound()返回值
- LINUX 下 JNA 调用 so--正确版
- [模拟]uva993 Product of digits
- 从 Yarn 回滚到 Hadoop 1.x
- Oracle事务的ACID特性
- STM32学习笔记:通用定时器基本设定
- dundas legend checkbox
- 字符驱动程序框架
- 黑马程序员_多线程(二)