C++编程入门之十二(queue容器)

queue队列容器

1.1queue基本概念

C++编程入门之十二(queue容器)
C++编程入门之十二(queue容器)
C++编程入门之十二(queue容器)

1.2queue常用接口

C++编程入门之十二(queue容器)

#include"pch.h"
#include<iostream>
#include<string>
#include<opencv2/opencv.hpp>
#include<vector>
#include<algorithm> // 标准算法头文件
      
        
using namespace std;
using namespace cv;
class Person
{
public:
	Person(string name, int age)
	{
		this->m_Name = name;
		this->m_age = age;
	}
	string m_Name;
	int m_age;
};
//队列queue容器
void test01()
{
	//创建队列
	queue<Person>q;
	//准备数据
	Person p1("唐僧", 30);
	Person p2("孙悟空", 3000);
	Person p3("猪八戒", 300);
	Person p4("沙僧", 3);
	//入队
	q.push(p1);
	q.push(p2);
	q.push(p3);
	q.push(p4);
	cout << q.size() << endl;
	//判断队列是否为空,不空时查看队头和队尾,出队
	while (!q.empty())
	{
		//查看队头
		cout << "队头————姓名: " << q.front().m_Name <<"年龄:" <<q.front().m_age << endl;
		//查看队尾
		cout << "队尾————姓名: " << q.back().m_Name << "年龄: " << q.back().m_age << endl;
		q.pop();
	}
	cout << q.size() << endl;
}
int main()
{
	test01();
	system("pause");
	return 0;
}

C++编程入门之十二(queue容器)