queue容器

queue基本概念:

概念:queue是一种先进先出的数据结构,它有两个口
queue列队容器允许从一端新增元素,从另一端移除元素
queue列队中只有对头和队尾才可以被外界使用,因此队列不允许有遍历行为
queue队列中进数据称为————入队 push
queue队列中出数据称为————出队 pop

返回队头元素————front
返回队尾元素————back
判断队是否为空————empyt
返回队列大小————size

#include<iostream>
using namespace std;
#include<queue>
#include<string>

class Person
{
public:
	Person(string name, int age)
	{
		this->Name = name;
		this->Age = age;
	}
	

	string Name;
	int Age;

};

void test01()
{
	queue<Person>q;

	//准备数据
	Person p1("小明", 10);
	Person p2("小猪", 9);
	Person p3("小猴", 7);

	//入队
	q.push(p1);
	q.push(p2);
	q.push(p3);
	
	cout << "列队大小为:" << q.size() << endl;

	while (!q.empty())
	{
		//查看对头
		cout << "对头姓名:" << q.front().Name << "对头年龄:" << q.front().Age << endl;

		//查看队尾
		cout << "队尾姓名:" << q.back().Name << "队尾年龄:" << q.back().Age << endl;

		//出列
		q.pop();
	}
	cout << "队列大小为:" << q.size() << endl;
}



int main()
{
	test01();
	system("pause");
	return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值