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() { //初始化 ...
随机推荐
- Spring Boot中使用Swagger2构建RESTful APIs
关于 Swagger Swagger能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原因: Swagger 可以生成一个具有互动性的API控制台,开发者可以用来快速学习和尝试API. S ...
- cnetos7设置中文显示及中文输入法
Centos7安装的时候即使选择了中文安装,因为安装后并没有GUI,即使后来安装GUI后默认依旧是英文显示. 输入locale后显示的是 永久修改成中文:编辑/etc/profile.d/lang.s ...
- [转载]Oracle日期周详解IW
1 ORACLE中周相关知识描述 1.1 日期格式化函数 TO_CHAR(X [,FORMAT]):将X按FORMAT格式转换成字符串.X是一个日期,FORMAT是一个规定了X采用 ...
- Oracle GoldenGate 18.1 支持的DB和OS列表
Product Release Processor Type OS Version OS Update Type OS Update Level Run Mode 32/64 Bit Database ...
- 1、SpringBoot bean,list,map Json返回
1.Bean public class User { private int id; private String username; private String password; public ...
- vue 引入iconfont字体库
1.登录官网 https://www.iconfont.cn/ 2.选择所需要的图标加入图库 新建项目 选择fontClass 并下载到本地 目录如下 3.项目 assets目录下 新建 ico ...
- 使用QPlainText代替QText
1.现象 在项目开发中,经常使用QText来显示解析的数据,比如从网络中获取到一个数据包,解析成中文加以显示,当时间过久或者字符串比较多的时候,就会产生一定的卡顿,所以需要限制QText的行数,或者清 ...
- MySQL 增删改查
增--添加数据 新建数据库 create database newdatabase; 选择数据库 use newdatabase; 新建表 create table newtable(id int,n ...
- MySQL explain执行计划优化
https://www.linuxidc.com/Linux/2016-04/129965.htm
- 【转载】RESTful 架构风格概述
本文转载自https://blog.igevin.info/posts/restful-architecture-in-general/ 在移动互联网的大潮下,随着docker等技术的兴起,『微服务』 ...