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() { //初始化 ...
随机推荐
- python基础部分----基本数据类型
0.文章来源:http://www.cnblogs.com/jin-xin/articles/7562422.html 1.数字 2.bool 3.str字符串 3.1.字符串的索引与切片. 索引即下 ...
- [Offer收割] 编程练习赛1
A HihoCoder 1268 九宫 思路: 一般类似于数独的题目都是使用回溯解决,这里由于题目数据较小同样可以直接DFS得出结果.这里我用了一个偷懒的方法(next_permutation),直接 ...
- Unity入门一,什么是GameObject,MonoBehaviour
Unity入门一,什么是GameObject,MonoBehaviour GameObject和Component Unity是一个Component-Based的引擎,所有物体都是GameObjec ...
- NAT穿透的详解及分析
一.什么是NAT?为什么要使用NAT?NAT是将私有地址转换为合法IP地址的技术,通俗的讲就是将内网与内网通信时怎么将内网私有IP地址转换为可在网络中传播的合法IP地址.NAT的出现完美地解决了lP地 ...
- VueScroller 使用
下载插件 npm install vue-scroller -D 引入插件: import Vue from 'vue'import VueScroller from 'vue-scroller' ...
- 编程类-----matlab基础语法复习(1)
2019年美赛随笔记录: 具体功能:基础语法+基本运算+画图+矩阵+excel读取....... 所遇问题及其解决方案: 1. que:matlab中plot画图无法复制下来图片? ...
- dt转换List CovertListHelper
public class CovertListHelper { //传递过来的类型必须与数据库类型保持一致问题 public List<T> convertToList<T>( ...
- SPOJ COT Count on a tree(树上主席树 + LCA 求点第k小)题解
题意:n个点的树,每个点有权值,问你u~v路径第k小的点的权值是? 思路: 树上主席树就是每个点建一棵权值线段树,具体看JQ博客,LCA用倍增logn求出,具体原理看这里 树上主席树我每个点的存的是点 ...
- blogger添加代码高亮
blogger(blogspot)自带的是没有代码高亮的,我们可以用下面的方法添加代码高亮. 首先我们打开blogger(blogspot)后台,然后点击主题背景-->修改html,然后在弹出的 ...
- Dockerfile详解及优化
Dockerfile详解 0. Dockerfile的作用 docker可以根据Dockerfile中的指令来构建docker镜像.Dockerfile是一个文本文件,其应当包含用户想要构建一个镜像的 ...