STL——容器(deque)deque 的插入 insert()
deque.insert(pos,elem);
//在pos位置插入一个elem元素的拷贝,返回新数据的位置。
1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A, deqInt_B;
9
10 deqInt_A.push_back(1);
11 deqInt_A.push_back(2);
12 deqInt_A.push_back(3);
13
14 cout << "遍历deqInt_A" << endl;
15 for (deque<int>::iterator it = deqInt_A.begin(); it != deqInt_A.end(); it++)
16 {
17 cout << *it << " ";
18 }
19
20 //在首位置插入1个数
21 deqInt_A.insert(deqInt_A.begin(), 0);
22
23 cout << "\ninsert 插入后,遍历deqInt_A" << endl;
24 for (deque<int>::iterator it = deqInt_A.begin(); it!= deqInt_A.end(); it++)
25 {
26 cout << *it << " ";
27 }
28
29 return 0;
30 }
打印结果:
deque.insert(pos,n,elem);
//在pos位置插入n个elem数据,无返回值。
1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A, deqInt_B;
9
10 deqInt_A.push_back(1);
11 deqInt_A.push_back(2);
12 deqInt_A.push_back(3);
13
14 cout << "遍历deqInt_A" << endl;
15 for (deque<int>::iterator it = deqInt_A.begin(); it != deqInt_A.end(); it++)
16 {
17 cout << *it << " ";
18 }
19
20 //在首位置+1处 插入2个0
21 deqInt_A.insert(deqInt_A.begin() + 1, 2, 0);
22
23 cout << "\ninsert 插入后,遍历deqInt_A" << endl;
24 for (deque<int>::iterator it = deqInt_A.begin(); it!= deqInt_A.end(); it++)
25 {
26 cout << *it << " ";
27 }
28
29 return 0;
30 }
打印结果:
deque.insert(pos,beg,end);
//在pos位置插入[beg,end)区间的数据,无返回值
1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A, deqInt_B;
9
10 deqInt_A.push_back(1);
11 deqInt_A.push_back(2);
12 deqInt_A.push_back(3);
13
14 deqInt_B.push_back(10);
15 deqInt_B.push_back(20);
16 deqInt_B.push_back(30);
17
18 cout << "遍历deqInt_A" << endl;
19 for (deque<int>::iterator it = deqInt_A.begin(); it != deqInt_A.end(); it++)
20 {
21 cout << *it << " ";
22 }
23 cout << "\n遍历deqInt_B" << endl;
24 for (deque<int>::iterator it = deqInt_B.begin(); it != deqInt_B.end(); it++)
25 {
26 cout << *it << " ";
27 }
28
29 //在首位置+1处 插入deqInt_B
30 deqInt_A.insert(deqInt_A.begin() + 1, deqInt_B.begin(), deqInt_B.end());
31 cout << "\n在首位置+1处 插入deqInt_B" << endl;
32 for (deque<int>::iterator it = deqInt_A.begin(); it!= deqInt_A.end(); it++)
33 {
34 cout << *it << " ";
35 }
36
37 return 0;
38 }
打印结果:
===================================================================================================================
STL——容器(deque)deque 的插入 insert()的更多相关文章
- STL——容器(deque) 构造 & 头尾添加删除元素
1.deque容器概念 deque是"double-ended queue"的缩写,和vector一样都是STL的容器,唯一不同的是:deque是双端数组,而vector是单端的. ...
- STL——容器(Set & multiset) insert 的返回值 和 pair 的用法
1. 使用 insert 插入时的返回值: 将一个元素插入 (insert) 到 set 或 multiset 中时,如果插入失败返回的类型是一个 pair 的自定类型,insert 源码如下: in ...
- STL容器:deque双端队列学习
所谓deque,是"double-ended queue"的缩写; 它是一种动态数组形式,可以向两端发展,在尾部和头部插入元素非常迅速; 在中间插入元素比较费时,因为需要移动其它元 ...
- STL容器分析--deque
deque,故名思义,双向队列.可以在头尾进行插入删除. 而STL中采用了链表+线性表的数据结构来实现deque,因而除了满足双向队列的特点以外,还支持随机访问. 下面,贴一段代码. 总览:双向队列是 ...
- STL——容器(deque)deque 的删除 clear() erase()
deque.clear(); //移除容器的所有数据 1 #include <iostream> 2 #include <deque> 3 4 using namespace ...
- STL——容器(deque) deque 的大小
1. deque 的大小 deque.size(); //返回容器中元素的个数 1 #include <iostream> 2 #include <dequ ...
- STL——容器(deque) 元素的存取&迭代器
1. deque 的数据存取 这个部分和 vector 几乎一样 第一 使用下标操作 dequeName[0] = 100; //小心越界 第二 使用at 方法 如: dequeName.at(2 ...
- STL——容器(deque) deque 的赋值 assign() operator=() swap()
deque 的赋值分下边4种方法: deque.assign(beg,end); //将[beg, end)区间中的数据拷贝赋值给本身.注意该区间是左闭右开的区间. 1 #include <io ...
- STL容器存储的内容动态分配情况下的内存管理
主要分两种情况:存储的内容是指针:存储的内容是实际对象. 看以下两段代码, typedef pair<VirObjTYPE, std::list<CheckID>*> VirO ...
随机推荐
- 怎样禁止Ceph OSD的自动挂载
前言 本篇来源于群里一个人的问题,有没有办法让ceph的磁盘不自动挂载,一般人的问题都是怎样让ceph能够自动挂载,在centos 7 平台下 ceph jewel版本以后都是有自动挂载的处理的,这个 ...
- Python_科学计算平台__pypi体系的numpy、scipy、pandas、matplotlib库简介
1.numpy--基础,以矩阵为基础的数学计算模块,纯数学 存储和处理大型矩阵. 这个是很基础的扩展,其余的扩展都是以此为基础. 快速学习入口 https://docs.scipy.org/doc/n ...
- Vegas视频的音频叠加效果怎么实现,可以用其他软件吗
有时我们会用Vegas为某段影片配音,我们要怎么把配音和背景声融合在一起呢?想必马上会有人反应过来:让配音和背景声分别置于两条轨道上就好了.这当然是一个相当好的方式. 可是,如果我想要把两段音频合成一 ...
- ResNet模型
ReeNet论文地址:Deep Residual Learning for Image Recognition Resnet的两种不同结构 上图左边的结构主要是针对深度较少的网络,当深度较大时则用右边 ...
- miniconda安装及使用
conda环境配置 安装conda [清华源下载地址](https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/) 官网或百度云网盘下载对应版本 ...
- H3CNE认证(题库)
H3CNE考试的题库,均为发烧友收集的,拥有将近认证考试的百分之八十五的题,但答案不具备官方性,但是题库具有解析. https://huxiaoyao.lanzous.com/b01tr2skd 密码 ...
- zk特性
看了又忘系列: 1.zk会将全量的数据存储在内存中,以此来实现提高服务器吞吐,减少延迟的目的. 2.集群中每台机器都会在内存中维护当前的服务器状态,并且每台机器之间都相互保持着通信.只要集群中存在超过 ...
- 利用反射获取对象中的值等于x的字段
Field[] field = behavior.getClass().getDeclaredFields(); for (int i = 0; i < field.length; i++) { ...
- 冲刺随笔——Day_Eight
这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺 作业正文 正文 其他参考文献 无 ...
- Android的Toolbar(含溢出菜单设置[弹出菜单的使用])的使用PopMenu的样式
http://blog.csdn.net/yingtian648/article/details/52432438(转载) 1.在Toolbar.xml中设置弹出菜单的风格(app:popupThem ...