当前位置:网站首页>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;
}
边栏推荐
- 成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析
- 动态规划问题 - 小兵向前冲
- ENVI_IDL:批量拼接Modis Swath的逐日数据并输出为Geotiff格式
- Uncaught syntaxerror: unexpected token '< is reported on the blank page of the H5 uniapp package‘
- Lintcode 366:Fibonacci 斐波那契数列
- 博客里《DSAA》相关文章的代码
- Pointer constant and constant pointer love and hate
- How to understand volatile and how to use it
- Clion 安装以及中开发ROS实现自动提示补全
- gdb+vscode进行调试2——gdb断点相关
猜你喜欢

gdb+vscode进行调试4——gdb执行相关命令

STL--stack容器

vscode+ros2环境配置

Chengxin University envi_ IDL third week class content 1: reading OMI data (HDF5 file) and output + parsing

Envi IDL: lire la teneur en colonne de NO2 de tous les produits OMI et calculer la moyenne mensuelle, la moyenne trimestrielle, la moyenne annuelle + résolution

ENVI_IDL:讀取所有OMI產品的NO2柱含量並計算月均值、季均值、年均值+解析

【解决方案】win11中本地组策略编辑器(gpedit.msc)打不开

ENVI_IDL:批量拼接Modis Swath的逐日数据并输出为Geotiff格式

ENVI_ Idl: batch Reproject MODIS swath products and specify the range output as GeoTIFF format + parsing

ENVI_ IDL: read OMI data (HDF5) and output it as GeoTIFF file + detailed parsing
随机推荐
leetcode力扣经典题目——82.柱形图中的最大矩形
信号与系统实验
LeetCode:动态规划中的子序列问题
Memory pooling of pooled components
Hue oozie editor scheduling shell
Original code, inverse code, complement code
BladeX——精心设计的微服务架构
Opengauss Developer Day 2022 dongfangtong sincerely invites you to visit the "dongfangtong ecological tools sub forum"
RuntimeError_ Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor)
switch详解
Envi IDL: lire la teneur en colonne de NO2 de tous les produits OMI et calculer la moyenne mensuelle, la moyenne trimestrielle, la moyenne annuelle + résolution
Foo bar 什么鬼?
搭建Sqoop环境
Can protocol communication
[dynamic planning hundred questions strengthening plan] 1~10 (continuously updating)
Build map reduce development environment
Swagger——世界上最流行的Api框架
ENVI_IDL: 读取文本文件并输出为Geotiff格式+简单均值插值
Engineering compilation: makefile and cmake (I)
Differences between saber PSPICE Simulink power supply simulation software