1. deque 的大小

  • deque.size();              //返回容器中元素的个数
 1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A;
9 deqInt_A.assign(4, 111);
10
11 cout << "deqInt_A 中的元素个数为:"<< deqInt_A.size() << endl;
12
13 return 0;
14 }

打印结果:

  • deque.empty();       //判断容器是否为空
 1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A,deqInt_B;
9 deqInt_A.assign(4, 111);
10
11 if (deqInt_A.empty())
12 {
13 cout << "deqInt_A 为空" << endl;
14 }
15 else
16 {
17 cout << "deqInt_A 不为空" << endl;
18 }
19 if (deqInt_B.empty())
20 {
21 cout << "deqInt_B 为空" << endl;
22 }
23 else
24 {
25 cout << "deqInt_B 不为空" << endl;
26 }
27
28 return 0;
29 }

打印结果

  • deque.resize(num);       //重新指定容器的长度为num,若容器变长,则以默认值0填充新位置。如果容器变短,则末尾超出容器长度的元素被删除。
 1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A;
9 deqInt_A.assign(5, 111);
10
11 for (deque<int>::iterator it = deqInt_A.begin(); it!= deqInt_A.end(); it++)
12 {
13 cout << *it << " ";
14 }
15
16 cout << "\n使用 resize 扩容" << endl;
17 deqInt_A.resize(10);
18 for (deque<int>::iterator it = deqInt_A.begin(); it != deqInt_A.end(); it++)
19 {
20 cout << *it << " ";
21 }
22
23 return 0;
24 }

打印结果:

  • deque.resize(num, elem);  //重新指定容器的长度为num,若容器变长,则以elem值填充新位置。如果容器变短,则末尾超出容器长度的元素被删除。
 1 #include <iostream>
2 #include <deque>
3
4 using namespace std;
5
6 int main()
7 {
8 deque<int> deqInt_A;
9 deqInt_A.assign(5, 111);
10
11 for (deque<int>::iterator it = deqInt_A.begin(); it!= deqInt_A.end(); it++)
12 {
13 cout << *it << " ";
14 }
15
16 cout << "\n使用 resize 扩容" << endl;
17 deqInt_A.resize(10, 222);
18 for (deque<int>::iterator it = deqInt_A.begin(); it != deqInt_A.end(); it++)
19 {
20 cout << *it << " ";
21 }
22
23 return 0;
24 }

打印结果:

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

STL——容器(deque) deque 的大小的更多相关文章

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

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

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

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

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

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

  4. STL容器分析--deque

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

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

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

  6. STL——容器(deque)deque 的插入 insert()

    deque.insert(pos,elem); //在pos位置插入一个elem元素的拷贝,返回新数据的位置. 1 #include <iostream> 2 #include <d ...

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

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

  8. ACM常用STL容器

    // STL(标准模板库),由三大部分组成:容器,算法,迭代器 // STL六大组件:container(容器),algorthm(算法),iterator(迭代器) // function obje ...

  9. STL vector容器 和deque容器

    前言 STL是C++的框架,然后vector容器和deque容器又是STL的一部分... 这块的内容都是理解.概念为主,没什么捷径,希望读者能静下来记. 先来讲vector容器(单端动态数组) 1.v ...

随机推荐

  1. SQL 查找"存在",别再用 count 了,很耗费时间的!

    根据某一条件从数据库表中查询 『有』与『没有』,只有两种状态,那为什么在写SQL的时候,还要SELECT count(*) 呢? 无论是刚入道的程序员新星,还是精湛沙场多年的程序员老白,都是一如既往的 ...

  2. ubuntu 18.04安装RTL8821CE无线网卡驱动

    疫情期间闲下来无聊,把办公室的旧机器装了ubuntu,但是无法连接无线网. 打开终端 #查看无线网卡信息. -i 是不区分大小写 tjj@ubuntu:~/Documents$ lspci | gre ...

  3. ServiceStack.Redis 的 ASP.NET Core 扩展库

    给大家安利一款 ServiceStack.Redis 的 ASP.NET Core 扩展库,它是基于 ServiceStack.Redis.Core 开发的. 简单易用,开源免费,使用ASP.NET ...

  4. Metasploit渗透使用攻略

    msf关于tomcat口令暴力猜解模块 use auxiliary/scanner/http/tomcat_mgr_login show options set rhosts 192.168.2.14 ...

  5. kali 系列学习02 - 被动扫描

    被动扫描是指目标无法察觉的情况下进行信息收集,注意有经验的渗透工程师会在信息收集上花费整个测试过程一半以上的时间,信息量太大,需要自动化的信息收集工具. 一.借鉴<kali linux2 网络渗 ...

  6. Android ALSPS驱动分析

    一.alsps的初始化函数和重要结构体 epl2182_init // Epl2182.c (kernel-3.10\drivers\misc\mediatek\alsps\epl2182-new) ...

  7. FL Slayer合成器功能之顶部组件介绍

    本章节采用图文结合的方式给大家介绍电音编曲软件--FL Studio中的插件FL Slayer合成器中的顶部组件,它是电吉他模拟合成器,感兴趣的朋友可以一起沟通学习交流. FL Slayer(杀手)合 ...

  8. python3安装mysqlclient,解决django使用pymysql报错的问题

    1.起因 在django中为了使用MySQL,一般是在项目目录下的__init__.py中添加 import pymysql pymysql.install_as_MySQLdb() # 使用pymy ...

  9. 一次SQL注入导致的"越权"

    原文来自SecIN社区-作者:tkswifty 相关背景   在实际的业务开发中,SQL交互往往是业务系统中不可或缺的一项.在Java中提供了类似Mybatis.Hibernate.SpringDat ...

  10. cert-manager管理内网k8s开发环境证书

    目的 内网k8s开发环境配置HTTPS,保持与生产环境的配置的一致性,其必要性有: PWA开发,HTTPS是必要条件 网页引入HTTP资源,如果开发环境是HTTP就不会被开发和测试人员发现,造成生产环 ...