set的lower_bound函数逆序
时间: 2023-10-14 19:03:24 浏览: 107
lower-bound函数2.zip
set的lower_bound函数是按照从小到大的顺序返回大于或等于给定值的第一个元素的迭代器。如果你想要逆序,可以使用set的reverse_iterator来遍历集合并输出元素。你可以参考下面的代码示例:
```cpp
#include <iostream>
#include <set>
int main() {
std::set<int> myset = {21, 64, 17, 78, 49};
std::set<int>::reverse_iterator rit;
std::cout << "myset contains: ";
for (rit = myset.rbegin(); rit != myset.rend(); ++rit) {
std::cout << *rit << ' ';
}
std::cout << '\n';
return 0;
}
```
这段代码首先创建了一个set并初始化了一些元素。然后使用reverse_iterator来逆序遍历set并输出元素。输出结果为:78 64 49 21 17。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [c++ set 的常见操作](https://blog.csdn.net/qq_45752450/article/details/107459429)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [杂记1:正向反向迭代器,不同stl容器的lower_bound的使用(set,map,vector,arr,pair),数字转字符串](https://blog.csdn.net/weixin_50816938/article/details/123942734)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文