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() { //初始化 ...
随机推荐
- [转载]Oracle用户创建及权限设置
出处:https://www.cnblogs.com/buxingzhelyd/p/7865194.html 权限: create session 允许用户登录数据库权限 create table ...
- java RSA实现私钥签名、公钥验签、私钥加密数据、公钥解密数据
通过OpenSSL生成公私钥文件(如果没有OpenSSL工具建议下载Cmder工具自带OpenSSL指令) 1.生成RSA密钥的方法 genrsa -out private-rsa.key 2048 ...
- win10电脑只有自带浏览器能上网
今天遇到了个奇葩问题,开机后登陆微信,怎么也登陆不上,用360检测,修复不了,找来大神一枚,打开我的Edge浏览器,各种网页浏览正常.......就告诉我就修好了.WTF!!! 现象:只有自带浏览器能 ...
- QSettings 类
一 .QSettings介绍: 用户通常希望应用程序记住其设置.在windows中,这些设置保存在注册表中,ios在属性文件列表中,而unix,在缺乏标准的情况下,其存储在ini文本中.QSettin ...
- Windows10 引导修复
[问题]最近遇到一些用户使用的操作系统为Win10,但是使用过程中由于错误系统优化.卸载软件错误.误删系统文件.windows更新错误等,影响系统BCD引导文件,造成开机出现该BCD蓝屏报错,如下图所 ...
- Spring发送邮件
Spring邮件发送流程:第一步:邮件发送,需要一个邮件服务器.可以使用腾讯获得网易的邮件服务器.登录邮箱,点击左上角的设置,再点击账号 找到下列选项,点击开启,需要发短信验证,或者使用QQ安全登录扫 ...
- Java线程基础(二)
今天上午考完了计算机二级,也算卸掉了一个大包袱吧,希望能过!(其实也就考着玩的,不来点考试就要发霉了) 好了,趁着难得的考后休息时间我就接着上一次没写完的继续更新吧. 上一篇文章——>Java核 ...
- ORACLE——RMAN 参数解读
查看默认rman配置参数 oracle用户下登录rman:rman target / 查看所有配置参数详情:show all show all的第一行:using target database co ...
- eclipse改jsp文件编码格式 统一设置
- BZOJ-2298|区间dp|线段树
problem a Description 一次考试共有n个人参加,第i个人说:"有ai个人分数比我高,bi个人分数比我低."问最少有几个人没有说真话(可能有相同的分数) Inpu ...