1.queue容器基本概念
2.queue常用接口
#include <iostream>
using namespace std;
//队列queue
#include<queue>
//创建Person类
class Person
{
public:
Person(string name, int age)
{
this->m_Name = name;
this->m_Age = age;
}
string m_Name; //姓名
int m_Age; //年龄
};
void test01()
{
//创建西游记人物对象
Person p1("唐僧", 30);
Person p2("孙悟空", 1000);
Person p3("猪八戒", 800);
Person p4("沙僧", 600);
//创建队列queue
queue<Person>q;
//入队
q.push(p1);
q.push(p2);
q.push(p3);
q.push(p4);
cout << "队列queue大小为:" << q.size() << endl;
//判断queue有没有空,没空往下执行
while (!q.empty())
{
//输出队头队尾
cout << "队头元素姓名为:" << q.front().m_Name << "\t\t年龄为:" << q.front().m_Age << endl;
cout << "队尾元素姓名为:" << q.back().m_Name << "\t\t年龄为:" << q.back().m_Age << endl;
//出队
q.pop();
}
cout << "队列queue大小为:" << q.size() << endl;
}
int main()
{
test01();
//**************************************
system("pause");
return 0;
}