当前位置:网站首页>STL--queue容器
STL--queue容器
2022-07-17 00:13:00 【hjl011006】
一、queue基本概念
- 概念:queue是一种先进先出的数据结构,他有两个出口
- 图片:

- 特点:
队列容器允许从一端新增元素,从另一端移除元素
队列只有队头和队尾才可以被外界使用,因此队列不允许有遍历行为
队列中进数据称为----入队 (push)
队列中出数据称为----出队 (pop)
二、queue的常用接口
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
class person
{
public:
person(string name,int age)
{
this->name=name;
this->age=age;
}
string name;
int age;
};
int main()
{
// 特点:符合先进先出的数据结构
queue<person> q;
person p1("唐僧",30);
person p2("孙悟空",600);
person p3("猪八戒",400);
person p4("沙悟净",300);
// 入队
q.push(p1);
q.push(p2);
q.push(p3);
q.push(p4);
// 队列大小
cout<<"队列大小:"<<q.size()<<endl;
// 判断队列不为空,查看队首队尾是谁
while(!q.empty())
{
cout<<"队首是:\t"<<"姓名:"<<q.front().name<<"\t年龄:"<<q.front().age<<endl;
cout<<"队尾是:\t"<<"姓名:"<<q.back().name<<"\t年龄:"<<q.back().age<<endl;
//出队
q.pop();
// 队列大小
cout<<"队列大小:"<<q.size()<<endl;
}
return 0;
}
边栏推荐
猜你喜欢

Basic principle and parameter interpretation of operational amplifier

Line process of pool components

二叉树的遍历

06 design of smart electronic medicine box based on stm32

gdb+vscode进行调试5——gdb查看相关命令

成信大ENVI_IDL第三周课堂内容1:读取OMI数据(HDF5文件)以及输出+解析

成信大ENVI_IDL第一周实验测试:数组的简单运算+详细解析

gdb+vscode进行调试2——gdb断点相关

ENVI_IDL:批量对Modis Swath产品进行均值运算+解析

Can protocol communication
随机推荐
Swagger——世界上最流行的Api框架
成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析
gdb+vscode进行调试6——gdb调试多线程命令札记
Dueling DQN的理论基础及其代码实现【Pytorch + Pendulum-v0】
Nacos configuration management
ENVI_ Idl: batch splice the daily data of MODIS swath and output it in GeoTIFF format
【解决方案】win11中本地组策略编辑器(gpedit.msc)打不开
Vmware Tools最新安装教程(RHEL8)
笔记:光源选型与应用
YYDS! The latest distributed core technology notes summarized by Alibaba technical officers have been launched, which can be regarded as a blessing
Characteristics and application points of electrolytic capacitor
Nacos配置管理
STL--stack容器
Difference between close and shutdown
02 design of smart home system based on ZigBee
03 design of urban road dedusting and cooling system based on ZigBee
在Oozie中配置 map-reduce workflow
VS Code 问题:launch:program‘...\.vscode\launch.exe‘ dose not exist
原码,反码,补码
SAE J1708/J1587 协议详解