STL-queue

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值