当前位置:网站首页>Set container
Set container
2022-07-06 13:21:00 【Rivers overflow】
#include<set>
using std::set;
set Containers that can be automatically ordered internally and do not contain duplicate elements
1.set The definition of
set<typename> name;
Precautions are the same vector
2.set Access to elements within a container
differ vector,set Inner elements can only be accessed through iterators , And it does not support the behavior of iterators adding integers , Such as (it+i)i Writing as an integer is not allowed
The traversal method can only be
for(set<int>::iterator it=si.begin();it!=si.end();it++)
cout<<*it<<endl;
Be careful : Iterator not supported it<si.end() How to write it
3.set Common function analysis
(1)insert()
insert(x) take x Insert set In the container , And automatically incremental sorting and de duplication , The time complexity is O(logn),n by set The number of elements in
(2)find()
find(value) The return corresponding value is value The iterator , The time complexity is O(logn),n by set The number of elements in
set<int>::iterator it=set.find(3);// The return corresponding value is 3 The iterator
(3)erase()
①si.erase(it),it Iterator for the element to be deleted . The time complexity is O(1), Can be combined with find() Use
si.erase(si.find(200));// The deletion value is 200 The elements of ,erase by O(1),find by O(logn)
②si.erase(value),value For a value . Delete value value The elements of , Time complexity O(logn)
si.erase(200);// The deletion value is 200 The elements of , Time complexity O(logn)
③si.erase(first,last), Delete [first,last) Elements of left closed and right open intervals , Time complexity O(last-first)
set<int>::iterator it=si.find(30);
si.erase(it,si.end());
(4)size()
Time complexity O(1)
(5)clear()
Time complexity O(n)
4. Common use
Automatic de duplication and ascending sort
If you need to use the case without weight removal , Use multiset
If you need to use the case of no sorting , Use unordered_set( Much faster than set)
边栏推荐
- Fairygui bar subfamily (scroll bar, slider, progress bar)
- Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
- 分支语句和循环语句
- A brief introduction to the database of tyut Taiyuan University of technology in previous years
- View UI Plus 发布 1.3.0 版本,新增 Space、$ImagePreview 组件
- TYUT太原理工大学2022软工导论简答题
- TYUT太原理工大学2022软工导论考试题型大纲
- 4.30动态内存分配笔记
- 面渣逆袭:Redis连环五十二问,三万字+八十图详解。
- TYUT太原理工大学2022软工导论大题汇总
猜你喜欢
Fairygui bar subfamily (scroll bar, slider, progress bar)
十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
Decomposition relation model of the 2022 database of tyut Taiyuan University of Technology
国企秋招经验总结
西安电子科技大学22学年上学期《基础实验》试题及答案
如何保障 MySQL 和 Redis 的数据一致性?
Database operation of tyut Taiyuan University of technology 2022 database
(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
Heap sort [handwritten small root heap]
随机推荐
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
系统设计学习(三)Design Amazon‘s sales rank by category feature
4.30 dynamic memory allocation notes
System design learning (I) design pastebin com (or Bit.ly)
Fairygui bar subfamily (scroll bar, slider, progress bar)
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
The overseas sales of Xiaomi mobile phones are nearly 140million, which may explain why Xiaomi ov doesn't need Hongmeng
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
TYUT太原理工大学2022数据库大题之E-R图转关系模式
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
Tyut Taiyuan University of technology 2022 introduction to software engineering
抽象类和接口
Iterable、Collection、List 的常见方法签名以及含义
Tyut outline of 2022 database examination of Taiyuan University of Technology
(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
Rich Shenzhen people and renting Shenzhen people
架构师怎样绘制系统架构蓝图?
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
13 power map