1.符合先进先出的数据结构,允许从一端新增元素,另一端移除元素,除队头和尾之外其他元素不能被访问,不允许遍历,没有迭 代器
2.大小size
3.是否为空empty
4.队头元素 front
5.队尾元素back
6.入队push
7.出队pop
8.接口测试程序
#include "pch.h"
#include <iostream>
#include<queue>
#include<string>
using namespace std;
class Person
{
public:
string m_Name;
int m_Ae;
Person(string name, int age)
{
m_Name = name;
m_Ae = age;
}
};
void test01()
{
queue<Person>q;
Person p1("aaa", 10);
Person p2("bbb", 20);
Person p3("ccc", 30);
Person p4("ddd", 40);
//入队
q.push(p1);
q.push(p2);
q.push(p3);
q.push(p4);
while (!q.empty())
{
//获取队头元素
cout <<"队头元素name: "<< q.front().m_Name
<<" Age: "<<q.front().m_Ae<< endl;
//获取队尾元素
cout << "队尾元素name: " << q.back().m_Name
<< " Age: " << q.back().m_Ae << endl;
//出队
q.pop();
}
cout << "队列大小: " << q.size();
}
int main()
{
test01();
}