upper_bound()返回值
来源:互联网 发布:闵玧其知乎 编辑:程序博客网 时间:2024/05/22 16:23
函数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 ;}
- 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
- wcf客户间通信
- 1835
- 在VC++中读写INI文件
- java读文件学习笔记
- TCP/IP 学习心得
- upper_bound()返回值
- PIO模式
- eclipse中如何本地安装ADT
- c语言预处理
- C#事件(event)解析
- Linux终端使用技巧
- 2011-08-31[省市区3级级联js代码]
- 微内核和宏内核
- 初步了解Ajax技术