STL之Queue容器
容器 STL Queue
2023-09-11 14:21:07 时间
1.Queue容器
1)queue是队列容器,是一种“先进先出”的容器。
2)queue是简单地装饰deque容器而成为另外的一种容器。
3)头文件。#include <queue>
2.queue对象的默认构造
queue采用模板类实现,queue对象的默认构造形式:queue<T> queT; 如:
queue<int> queInt; //一个存放int的queue容器。
queue<float> queFloat; //一个存放float的queue容器。
queue<string> queString; //一个存放string的queue容器。
...
//尖括号内还可以设置指针类型或自定义类型。
3.queue的push()与pop()方法
queue.push(elem); //往队尾添加元素
queue.pop(); //从队头移除第一个元素
queue<int> queInt; queInt.push(1);queInt.push(3); queInt.push(5);queInt.push(7); queInt.push(9);queInt.pop(); queInt.pop(); 此时queInt存放的元素是5,7,9
4.queue对象的拷贝构造与赋值
queue(const queue &que); //拷贝构造函数
queue& operator=(const queue &que); //重载等号操作符
queue<int> queIntA; queIntA.push(1); queIntA.push(3); queIntA.push(5); queIntA.push(7); queIntA.push(9); queue<int> queIntB(queIntA); //拷贝构造 queue<int> queIntC; queIntC = queIntA; //赋值
5.queue的数据存取
queue.back(); //返回最后一个元素
queue.front(); //返回第一个元素
queue<int> queIntA; queIntA.push(1); queIntA.push(3); queIntA.push(5); queIntA.push(7); queIntA.push(9); int iFront = queIntA.front(); //1 int iBack = queIntA.back(); //9 queIntA.front() = 11; //11 queIntA.back() = 19; //19
6.queue的大小
queue.empty(); //判断队列是否为空
queue.size(); //返回队列的大小
queIntA.push(1); queIntA.push(3); queIntA.push(5); queIntA.push(7); queIntA.push(9); if (!queIntA.empty()) { int iSize = queIntA.size(); //5 }
相关文章
- 《Java并发编程实战》第五章 同步容器类 读书笔记
- 一文带你了解K8S 容器编排(下)
- C/C++知识要点2——STL中Vector、Map、Set容器的实现原理
- STL之关联容器的映射底层
- 81 C++ - STL容器使用时机
- 如何在一个Docker容器里安装Discourse
- docker及docker-compose的离线安装与镜像及容器的导入、导出操作总结
- 涨薪秘籍!阿里限产新一代微服务 +K8S+ 容器进阶笔记,实战理论满满
- Spring为IOC容器注入Bean的五种方式
- STL - 容器 - UnorderedSet(一)
- STL - 容器 - Forward List
- STL - 容器 - vector简单应用
- 容器OOM相关
- 【C++ STL学习之五】容器set和multiset
- C++ STL基本容器的使用
- 【C++】deque容器、stack容器&queue容器
- 详解C++ STL map 容器
- 浅谈C++ STL vector 容器
- STL之vector容器的实现框架
- STL之stack容器
- dcoker之容器数据卷,以及定制镜像Dockerfile配置与设置
- 编程参考 - C++ STL 容器概览