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() { //初始化 ...
随机推荐
- python3 短网址和数字的相互转换的代码
下面内容是关于python3 短网址和数字的相互转换的内容. import mathimport decimal def convert_to_code(num): """ ...
- java 几个实用的小工具
1.除法运算 编程的人都知道,java中的“/”.“%”运算,其中前者为取整,后者取余数.那么有没有快捷的运算方法取正常的运算结果呢? 查了资料,发现很简单.代码如下: public static S ...
- CCF CSP 201609-1 最大波动
题目链接:http://118.190.20.162/view.page?gpid=T47 问题描述 试题编号: 201609-1 试题名称: 最大波动 时间限制: 1.0s 内存限制: 256.0M ...
- 关于Axure RP软件的介绍——软件工程实践第二次个人作业
关于Axure RP软件的介绍——软件工程实践第二次个人作业 Axure RP是一个非常专业的快速原型设计的一个工具,客户提出需求,然后根据需求定义和规格.设计功能和界面的专家能够快速创建应用软件或W ...
- QGraphicsItem的paint函数的一些相关问题
在QGraphicsItem中,一个成员函数paint(),其声明如下: void QGraphicsItem::paint ( QPainter * painter, const QStyleOpt ...
- 关于用IIS在.net平台发布网页的一些坑
说明:由于需要显示页面的表格的内容,要用pageOffice插件,而装pageoffice之前需要装.net3.5,直接导入. 为什么要分别装.net4.5和.net3.5 ? 都要装? 问题:刚才 ...
- pywinauto简单操作写字板的例子
前段时间写了做web程序界面自动化的简单例子,今天写一下windows gui程序界面自动化测例子吧. ps.咱中国人YinKaisheng封装的UIAutomation库也很好用,https://g ...
- 细数Linux的文件权限
普通权限 普通权限使用ls -l查看,最前面显示的即是,如: # ls -l .txt -rw-r--r-- 1 root root 8338 7月 19 20:27 1.txt 权限介绍: -/d/ ...
- Centos7通过SSH使用密钥实现免密登录
日常开发中,难免会有登录服务器的操作,而通过ssh方式登录无疑是比较方便的一种方式. 如果登录较频繁,使用密钥实现免密登录无疑更是方便中的方便.因此本文就简单说一说如何实现免密登录. 一.安装配置ss ...
- topcoder srm 635 div1
problem1 link 首先枚举长度$L$.然后计算每一段长度$L$的差值最大公约数,然后差值除以最大公约数的结果可以作为当前段的关键字.然后不同段就可以比较他们的关键字,一样就是可以转化的. p ...