当前位置:网站首页>STL set容器
STL set容器
2022-07-24 03:23:00 【joker_0030】
#include <set>
#include <string>
#include<iostream>
using namespace std;
int main()
{
set<string> db;
db.insert(string("abs"));
db.insert(string("abd"));
db.insert(string("abe"));
db.insert(string("abc"));
db.insert(string("aba"));
//删除。
db.erase(string("abe"));
//db.erase("abe");
//迭代器輸出
set<string>::iterator ite = db.begin();
for ( ite; ite !=db.end(); ite++)
{
cout << *ite<<endl;
}
system("pause");
return 0;
}
set:
1、關鍵字保存:通過實際值來排序,通過實際值來查找;
特點:a、高效訪問,對比map:
1、數據結構是紅黑樹;
2、map是分鍵值對,set鍵值即實際值,實際值即鍵值。
b、鍵值不能重複。
2、紅黑樹(平衡 排序二叉樹):x=log2^N:
a、N是數據總量。
b、x是查找次數,2^x>=N。
3、鍵值不能改,實際值可以改。但是一般修改實際值就是修改鍵值會使整個結構會發生改變,一般不提倡修改。
4、沒有容量;得到元素的個數,size(),尺寸;得到一個元素是否存在,或者判斷一個元素是否存在, count(const key&_key);判斷是否是空empty(),空返回1,非空返回0;迭代器,可以循環、也可以自加++,但不可以+2。
边栏推荐
- 水题: 接雨水
- What is the security of Treasury reverse repo
- Error code 0x80004005
- Acwing 4499. draw a circle (similar to a triangle)
- Lagrange polynomial
- FTP服务与配置
- Correct usage of iota in golang
- 实现两个页面之前的通信(使用localStorage)
- Qt自定义类使用自定义含参信号与槽
- Leetcode Hot 100 (Brush Topic 8) (232 / 88 / 451 / offer10 / offer22 / 344 /)
猜你喜欢

数据湖:开源数据湖方案DeltaLake、Hudi、Iceberg对比分析

In the future, when the interviewer asks why you don't recommend using select *, please answer him loudly!

JS small game running bear and cat source code

Cannot resolve symbol 'override' of idea clone‘

An introductory example of structure and combinatorial ideas in go language

Detailed explanation of wechat official account online customer service access methods and functions

Lagrange polynomial

JS 数组 isAarray() typeof

Realize the communication before two pages (using localstorage)

C动态内存管理详解
随机推荐
Insist on accompanying study
The function of SIP account - tell you what is SIP line
Lagrange polynomial
如何在 pyqt 中实现桌面歌词
Hospital PACS source code PACS ultrasonic Department source code DICOM image workstation source code [source code free sharing]
Correct usage of iota in golang
Services et configurations FTP
Industrial controller, do you really know your five insurances and one fund?
322. Change
拉格朗日插值法
JIRA automation experience sharing for 2 years
An introductory example of structure and combinatorial ideas in go language
Data Lake: comparative analysis of open source data Lake schemes deltalake, Hudi and iceberg
Cache component status when Vue components are switched, that is, dynamic components keep alive dynamic components and asynchronous components
How to write selenium's testng.xml
Redux Usage Summary
How does the small program mall refine the operation of members?
About Aries framework addition, deletion, modification and query - query demo
IDEA Clone的项目报Cannot resolve symbol ‘Override‘
关于Aries框架增删改查-查Demo