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 }

打印结果:

===================================================================================================================

最新文章

  1. textField设置输入文字距左边的距离
  2. NOIp 2012 #2 借教室 Label:区间修改线段树
  3. Xcode 创建静态库和动态库
  4. WPF中使用ValueConverter来实现“范围条件触发器”
  5. ubuntu安装kernel3.10.34
  6. SwapEffect 枚举(定义交换效果)
  7. Spring框架整合Struts2
  8. Stooge排序
  9. HTTP发送请求模拟
  10. html常见标签使用
  11. 在ubuntu中为navicat创建快捷方式
  12. .11-Vue源码之patch(1)
  13. maven导入外部jar包的方法
  14. css Margin-top塌陷,解决方法
  15. 吴裕雄 python 机器学习——线性回归模型
  16. jQuery使用(六):DOM操作之元素包裹、克隆DOM与data的综合应用
  17. CF 494B 【Obsessive String】
  18. hdoj:2031
  19. a标签总结
  20. Win2012&amp;Win2008双系统启动菜单设置

热门文章

  1. Docker学习6:使用docker构建Jekyll服务和java服务
  2. tp5获取当前域名
  3. 面试必看!凭借着这份 MySQL 高频面试题,我拿到了京东,字节的offer!
  4. 如何调整MathType公式的字体大小
  5. 用过MindManager后才知道思维导图原来这么简单
  6. 有什么好用的Mac数据恢复软件
  7. Jmeter生成HTML测试报告
  8. 这份SpringMVC执行原理笔记,建议做java开发的好好看看,总结的很详细!
  9. http host头攻击漏洞
  10. 【数学】康托展开 &amp;&amp; 康托逆展开