当前位置:网站首页>STL tutorial 10 container commonalities and usage scenarios
STL tutorial 10 container commonalities and usage scenarios
2022-07-03 11:45:00 【Sleepy snail】
Generality
- except queue And stack These two special containers with limited access , Each container provides functions that return iterators , Using the returned iterator, you can access the element .
- Usually STL No exceptions will be thrown . Ask the user to ensure that the correct parameters are passed .
- Each container provides a default constructor and a default copy constructor .
- Size dependent construction method :1 size() Returns the number of elements in the container 2empty() Judge whether the container is empty
STL Container use timing
1)vector Use scenarios
For example, the storage of software history operation records , Historical record , Last record
2)deque Use scenarios
First in first out scenario , For example, the queuing system , The storage of the queue can adopt deque, Supports fast removal of headers , Quick addition of tail . If the vector, When the head end is removed , It moves a lot of data , Slow speed .
vector and deque Compare
- vector.at() Than deque.at() Efficient , such as vector.at(0) Is constant ,deque The starting position of is not fixed .
- If there are a lot of release operations ,vector It takes less time , This is related to the internal implementation of both .
- deque Support quick insertion and removal of head , This is a deque The advantages of .
3)list Use scenarios
For example, the storage of bus passengers , Passengers may get off at any time , Support frequent removal and insertion of elements with uncertain positions
4)set Use scenarios
For example, the storage of personal score records of mobile games , The storage requirements are arranged from high score to low score .
5)map Use scenarios
For example, press ID Number stores 100000 users , If you want to be fast, you have to pass ID Find the corresponding user . Search efficiency of binary tree , This is reflected . If it is vector Containers , In the worst case, you may have to traverse the entire container to find the user .
边栏推荐
- ASP.NET-酒店管理系统
- How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
- Cacti监控Redis实现过程
- Cadence background color setting
- P3250 [HNOI2016] 网络 + [NECPC2022] F.Tree Path 树剖+线段树维护堆
- Multi dimensional monitoring: the data base of intelligent monitoring
- Arctangent entropy: the latest SCI paper in July 2022
- uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
- Double linked list of linear list
- Xml的(DTD,xml解析,xml建模)
猜你喜欢
随机推荐
2022年湖南工学院ACM集训第二次周测题解
同事写了一个责任链模式,bug无数...
优化接口性能
OpenStack中的测试分类
mysql使用update联表更新的方法
Machine learning 3.2 decision tree model learning notes (to be supplemented)
This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
PHP server interacts with redis with a large number of close_ Wait analysis
The excel table is transferred to word, and the table does not exceed the edge paper range
P3250 [HNOI2016] 网络 + [NECPC2022] F.Tree Path 树剖+线段树维护堆
牛牛的组队竞赛
Analysis of EPS electric steering system
cgroup简介
Kubernetes 三打探针及探针方式
DS90UB949
How to mix embedded MCU, arm and DSP?
typeScript
Excel快速跨表复制粘贴
Multi dimensional monitoring: the data base of intelligent monitoring
After setting up ADG, instance 2 cannot start ora-29760: instance_ number parameter not specified