当前位置:网站首页>STL-deque
STL-deque
2022-08-10 22:30:00 【Rice white】
deque简介
deque是双端数组,而vector是单端的.
deque在接口上和vector非常相似,在许多操作的地方可以直接替换
deque可以随机存取元素(at() [])
dequeIn the head and tail added or mobile elements very fast
deque对象的默认构造
deque采用模板类实现,deque对象的默认构造形式: deque<T>deqT;
dequeThe tail add remove operation
deque.push_back(elem); //在容器尾部添加一个数据
deque.push_front(elem); //在容器头部插入一个数据
deque.pop_back(); //删除容器最后一个数据
deque.pop_push(); //删除容器第一个数据
deque的数据存取
deque.at(index); //越界抛出异常 out_of_range
deque[index]; //越界不会抛出异常,直接报错
deque.front(); //返回第一个数据
deque.back(); //返回最后一个数据
deque迭代器
deque.begin(); //返回容器中第一个元素的迭代器
deque.end(); //返回容器中最后一个元素之后的迭代器
deque.rbegin(); //返回容器中倒数第一个元素的迭代器
deque.rend(); //Returns the last element from bottom element iterator
for(deque<int>::iterator it=deq.begin();it!=deq.end();++it)
{
cout<<*it<<endl;
}
for(deque<int>::reverse_iterator rit=deq.rbegin();it!=deq.rend();++rit)
{
cout<<*rit<<endl;
}
deque对象的带参构造函数
deque(beg,end) //左闭右开 [beg,end)
deque(n,elem) //构造函数将n个elem拷贝给本身
deque(const deque &deq) //拷贝构造函数
deque的赋值
deque.assign(beg,end) //左闭右开
deque.assign(n,elem) //将 n 个elem拷贝赋值给本身
deque& operator=(const deque &deq) //重载等号操作符
deque.swap(deq) //将deq与本身的元素互换
deque的大小
deque.size() //返回容器中元素的个数
deque.empty() //Determine the container release is empty
deque.resize(num) //重新指定容器的长度num
deque.resize(num,elem) //重新指定容器的长度为num,If the container by longerelem值填充
deque的插入
deque.insert(pos,elem) //在pos位置插入一个elem元素的拷贝,返回新数据的位置
deque.insert(pos,n,elem) //在pos位置插入n个elem数据,无返回值
deque.insert(pos,beg,end) //在pos位置插入[beg,end)区间的数据,无返回值
deque的删除
deque.clear() //移除容器的所有数据
deque.erase(beg,end) //删除[beg,end)区间的数据,返回下一个数据的位置
deque.erase(pos) //删除pos位置的数据,返回下一个数据的位置
边栏推荐
猜你喜欢
配电网络扩展规划:考虑使用概率性能源生产和消费概况的决策(Matlab代码实现)
c语言之 练习题1 大贤者福尔:魔法数,神奇的等式
电力系统潮流计算(牛顿-拉夫逊法、高斯-赛德尔法、快速解耦法)(Matlab代码实现)
使用 Cloudreve 搭建私有云盘
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
BM13判断一个链表是否为回文结构
FPGA - 7系列 FPGA内部结构之Memory Resources -03- 内置纠错功能
shell脚本循环语句for、while语句
H3C S5130 IRF做堆叠
3598. 二叉树遍历(华中科技大学考研机试题)
随机推荐
Labelme-5.0.1 version edit polygon crash
About DataFrame: Processing Time
测试4年感觉和1、2年时没什么不同?这和应届生有什么区别?
Shell programming specification and variables
The perfect alternative to domestic Gravatar avatars Cravatar
过滤器
阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展
为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?
TCP连接过程中如果拔掉网线会发生什么?
How to translate financial annual report, why choose a professional translation company?
直播课堂系统08补-腾讯云对象存储和课程分类管理
LeetCode-498 - Diagonal Traversal
Redis Performance Impact - Asynchronous Mechanisms and Response Latency
Likou 221 questions, the largest square
Alibaba and Ant Group launched OceanBase 4.0, a distributed database, with single-machine deployment performance exceeding MySQL
元宇宙社交应用,靠什么吸引用户「为爱发电」?
RADIUS Authentication Server Deployment Costs That Administrators Must Know
2022.8.9 Mock Competition
port forwarding
FPGA - Memory Resources of 7 Series FPGA Internal Structure -03- Built-in Error Correction Function