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()的更多相关文章

  1. STL——容器(deque) 构造 & 头尾添加删除元素

    1.deque容器概念 deque是"double-ended queue"的缩写,和vector一样都是STL的容器,唯一不同的是:deque是双端数组,而vector是单端的. ...

  2. STL——容器(Set & multiset) insert 的返回值 和 pair 的用法

    1. 使用 insert 插入时的返回值: 将一个元素插入 (insert) 到 set 或 multiset 中时,如果插入失败返回的类型是一个 pair 的自定类型,insert 源码如下: in ...

  3. STL容器:deque双端队列学习

    所谓deque,是"double-ended queue"的缩写; 它是一种动态数组形式,可以向两端发展,在尾部和头部插入元素非常迅速; 在中间插入元素比较费时,因为需要移动其它元 ...

  4. STL容器分析--deque

    deque,故名思义,双向队列.可以在头尾进行插入删除. 而STL中采用了链表+线性表的数据结构来实现deque,因而除了满足双向队列的特点以外,还支持随机访问. 下面,贴一段代码. 总览:双向队列是 ...

  5. STL——容器(deque)deque 的删除 clear() erase()

    deque.clear(); //移除容器的所有数据 1 #include <iostream> 2 #include <deque> 3 4 using namespace ...

  6. STL——容器(deque) deque 的大小

    1. deque 的大小 deque.size();              //返回容器中元素的个数 1 #include <iostream> 2 #include <dequ ...

  7. STL——容器(deque) 元素的存取&迭代器

    1. deque 的数据存取 这个部分和 vector 几乎一样 第一  使用下标操作 dequeName[0] = 100; //小心越界 第二  使用at 方法 如: dequeName.at(2 ...

  8. STL——容器(deque) deque 的赋值 assign() operator=() swap()

    deque 的赋值分下边4种方法: deque.assign(beg,end); //将[beg, end)区间中的数据拷贝赋值给本身.注意该区间是左闭右开的区间. 1 #include <io ...

  9. STL容器存储的内容动态分配情况下的内存管理

    主要分两种情况:存储的内容是指针:存储的内容是实际对象. 看以下两段代码, typedef pair<VirObjTYPE, std::list<CheckID>*> VirO ...

随机推荐

  1. 控制算法PID-理解分析1

    以下内容是来自网络上的,本人觉得有道理,拷贝下来,由于没有找到最源头的出处,没有注明来自何方. 转载,下面说法应该更通俗易懂一家庭,每次需要开支的时候丈夫P都要拿卡去取钱.需要多少取多少,因为银行最低 ...

  2. 重闯Sqli-labs关卡第三天(11-15关)

    前言 今天早上学了学网易云课堂的注入课程突然感觉网易云可i春秋联合出品的课程还不错,之后就刷了刷攻防世界的题,题有眉目但是还是忍不住看了WP 服了自己了!!!一直刷到了晚上也不知道几点我妈买了柚子回了 ...

  3. Go语言实现excel导入无限级菜单结构

    目录 需求 实现 测试 简单例子 复杂例子 需求 最近有一个需求,要实现一个无限级结构的树型菜单,差不多长下面这个样子 我们知道无限级实现思路都是用一个parent_id将各种层级串联起来,顶级的pa ...

  4. 面试官:小伙子,你给我说一下你对MySQL索引的理解吧

    一.索引是什么? 索引是帮助MySQL高效获取数据的数据结构. 二.索引能干什么? 索引非常关键,尤其是当表中的数据量越来越大时,索引对于性能的影响愈发重要.索引能够轻易将查询性能提高好几个数量级,总 ...

  5. 思维导图MindManager的过滤主题功能如何使用

    MindManager是一款多功能思维导图工具软件.但有的思维导图繁杂,用户只需要查看自己感兴趣的主题该怎么办呢?接下来,我就为大家详细介绍MindManager思维导图2020版的过滤主题功能,可以 ...

  6. MathType中的条件概率的输入

    条件概率公式是高中数学的概率知识中比较常用的一个公式,今天我们来介绍一下在MathType中如何输入条件概率公式. 具体步骤如下: 步骤一 打开专业的公式编辑软件MathType 7,在输入框中输入& ...

  7. Cypress系列(93)- Cypress.dom 命令详解

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 作用 与 DOM 元素相关的 helpe ...

  8. vue前端静态页面Github Pages线上预览实现

    一.前期准备之项目编译 此处记录如何解决vue2.0 打包之后,打开index.html出现空白页的问题,附上@参考地址 打包之前修改三个文件 第一步,找到build文件,在webpack.prod. ...

  9. sentinel整合dubbo

    <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-dubbo-a ...

  10. CentOS虚拟化尝试

    KVM ///确认cpu是否支持kvm,确认支持,主板还得开启VT和HT egrep '(vmx|svm)' --color=always /proc/cpuinfo ///yum安装rpm包 yum ...