当前位置:网站首页>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 .
边栏推荐
- Technical experts from large factories: how can engineers improve their communication skills?
- AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
- Go语言实现静态服务器
- Kubernetes 三打探针及探针方式
- How PHP solves the problem of high concurrency
- 用了这么久线程池,你真的知道如何合理配置线程数吗?
- How to make others fear you
- PHP基础
- 外插散点数据
- Keepalived中Master和Backup角色选举策略
猜你喜欢
随机推荐
AOSP ~ NTP ( 网络时间协议 )
How to become a senior digital IC Design Engineer (1-2) Verilog coding syntax: Verilog 1995, 2001, 2005 standards
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
按键切换:按F1-F12都需要按Fn
机器学习 3.2 决策树模型 学习笔记(待补)
R语言使用原生包(基础导入包、graphics)中的hist函数可视化直方图(histogram plot)
Oracle withdraw permission & create role
(数据库提权——Redis)Redis未授权访问漏洞总结
Asyncio warning deprecationwarning: there is no current event loop
mysql使用update联表更新的方法
Groovy测试类 和 Junit测试
外插散点数据
STL教程10-容器共性和使用场景
ftp登录时,报错“530 Login incorrect.Login failed”
R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
Go语言实现静态服务器
Excel表格转到Word中,表格不超边缘纸张范围
Analysis of EPS electric steering system
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
Visual Studio 2022下载及配置OpenCV4.5.5









