lower_bound,upper_bound

来源:互联网 发布:网络通信平台 编辑:程序博客网 时间:2024/05/22 14:00

代码

include

include

include

include

using namespace std;

int main()
{
std::vector data = { 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6 };

vector::iterator lower = std::lower_bound(data.begin(), data.end(), 1);
vector::iterator upper = std::upper_bound(data.begin(), data.end(), 7);

// do{
// cout << * lower << ” “;
// lower ++;
// }while(lower != upper);

cout << “================================” << endl;

// for(;lower != upper;lower ++){
// cout << * lower << ” “;
// }
// cout << endl;

copy(lower, upper, std::ostream_iterator(std::cout, ” “));

return 0;
}
结果
1 1 2 3 3 3 3 4 4 4 5 5 6

0 0
原创粉丝点击