STL 小白学习(8) set 二叉树
#include <iostream>
using namespace std;
#include <set> void printSet(set<int> s) {
for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
cout << *it << " ";
}
cout << endl;
}
//初始化
void test01(){
set<int> s1;//初始化
s1.insert();
s1.insert();
s1.insert();
s1.insert();
s1.insert();
s1.insert();
printSet(s1);//默认从小到大排序 //改变默认排序 }
//赋值操作
//等号重载 swap clear empty略
void test02() {
set<int> s1;//初始化
s1.insert();
s1.insert();
s1.insert();
s1.insert();
s1.insert();
s1.insert(); s1.erase(s1.begin());//根据迭代器位置进行删除
s1.erase();//删除指定元素
printSet(s1);
s1.erase(s1.begin(),s1.end());//根据迭代器位置进行删除
printSet(s1);
}
//查找操作
void test03() {
set<int> s1;
s1.insert();
s1.insert();
s1.insert();
set<int>::iterator ret = s1.find(); //find() 返回迭代器 没找到返回s1.end()
if (ret == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *ret << endl;
}
set<int>::iterator ret2 = s1.find(); //find() 返回迭代器 没找到返回s1.end()
if (ret2 == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *ret << endl;
} //lower_bound(keyElem) 存在keyElem返回迭代器 不存在 则返回最小的大于keyElem的迭代器
ret = s1.lower_bound();
if (ret == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *ret << endl;
} ret = s1.lower_bound();//查找12 没有12 返回最小的大于12的元素的迭代器
if (ret == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *ret << endl;
} //upper_bound(keyElem) 返回最小的大于keyElem的迭代器 不找keyElem
ret = s1.upper_bound();
if (ret == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *ret << endl;
} } //equal_range
void test04() {
set<int> s1 = { ,,,,, };
//equal_range 返回Lower_bound 和 upper_bound 的值
pair<set<int>::iterator, set<int>::iterator> myret = s1.equal_range();//pair
myret.first;//Lower_bound
myret.second;//upper_bound
if (myret.first == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *myret.first << endl;
}
if (myret.second == s1.end()) {
cout << "没有找到!" << endl;
}
else {
cout << "找到" << *myret.second << endl;
}
} int main() {
test04();
}
STL 小白学习(8) set 二叉树的更多相关文章
- STL 小白学习(1) 初步认识
#include <iostream> using namespace std; #include <vector> //动态数组 #include <algorithm ...
- STL 小白学习(10) map
map的构造函数 map<int, string> mapS; 数据的插入:用insert函数插入pair数据,下面举例说明 mapStudent.insert(pair<, &qu ...
- STL 小白学习(9) 对组
void test01() { //构造方法 pair<, ); cout << p1.first << p1.second << endl; pair< ...
- STL 小白学习(7) list
#include <iostream> using namespace std; #include <list> void printList(list<int>& ...
- STL 小白学习(5) stack栈
#include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace ...
- STL 小白学习(6) queue
//queue 一端插入 另一端删除 //不能遍历(不提供迭代器) 不支持随机访问 #include <queue> #include <iostream> using nam ...
- STL 小白学习(4) deque
#include <iostream> #include <deque> //deque容器 双口 using namespace std; void printDeque(d ...
- STL 小白学习(3) vector
#include <iostream> using namespace std; #include <vector> void printVector(vector<in ...
- STL 小白学习(2) string
#include <iostream> using namespace std; #include <string> //初始化操作 void test01() { //初始化 ...
随机推荐
- Android SDK Manager for Mac 在线更新镜像地址截至2017-10-01亲测有效
虽然国内google被墙了,但仍可利用国内的某些镜像网站实现Android SDK在线更新,使用方法如下: 1.启动 Android SDK Manager ,打开主界面,依次选择『Tools』.『O ...
- DUILIB UI创建过程
函数调用过程: CDialogBuilder 内部过程循环创建控件树 上图中 在AttachDialog中设置窗口的主控件 并设置控件树的pm
- C/C++中数据的存储
学java时了解到不同的数据在系统中存储的位置不一样,有的存在栈里,有的存在堆里.学C/C++时没注意过这个,最近学数据结构时遇到了问题:在定义一个结构体的指针时,系统如何给它分配的空间?从而让我想去 ...
- BindingResult 作用原理
controller代码 @RequestMapping("") public String index(@Valid User user , BindingResult bind ...
- Bootstrap的$(...).modal is not a function错误
使用模态对话框的时候报错了,$(...).modal is not a function 有点蒙,modal是boostrap的函数,而我已经导入了 然后在pycharm的terminal中看到了这一 ...
- windows下手动安装composer并配置环境变量
windows下手动安装composer并配置环境变量 转载地址: https://my.oschina.net/7sites/blog/209997 之前发表过一篇如何为composer设置代理 ...
- CustomScrollView
body: CustomScrollView( slivers: [ SliverList( delegate: SliverChildBuilderDelegate( (context, int i ...
- markdown test2
#home { width: auto; margin: 0 80px 0 0; } mkdir test. #include <msxml6.h> // 含有 MSXML最新版 #inc ...
- kali-通过获取路由器pin码套取无线网络密码shell脚本
直接上脚本吧, 我做个笔记. #************************************************************************* # > Fil ...
- Codeforces 101623E English Restaurant - 动态规划
题目传送门 传送门 题目大意 餐厅有$n$张桌子,第$i$张桌子可以容纳$c_i$个人,有$t$组客人,每组客人的人数等概率是$[1, g]$中的整数. 每来一组人数为$x$客人,餐厅如果能找到最小的 ...