#include <iostream>
#include <queue>
#include <string>
using namespace std;
class Person
{
public:
Person(string name, int age)
{
m_Name = name;
m_Age = age;
}
string m_Name;
int m_Age;
};
void test01()
{
//准备数据
Person p1("A", 10);
Person p2("B", 20);
Person p3("C", 30);
queue<Person> q;
q.push(p1);
q.push(p2);
q.push(p3);
//队列不提供迭代器,更不支持随即访问
while (!q.empty())
{
//输出队头元素
cout << q.front().m_Name << " " << q.front().m_Age << endl;
//弹出队头元素
q.pop();
}
}
int main(int argc, char const *argv[])
{
/*1. queue是一种先进先出(FIFO)的数据结构
2. 队列容器允许从一端新增元素,从另一端移出元素(入队,出队)
3. 队列中只有对头和对为才可以被外界使用,因此队列不允许有遍历行为
*/
test01();
return 0;
}
STL-queue
最新推荐文章于 2024-09-21 14:53:30 发布