队列与栈的输入输出

下面程序演示了队列FIFO和栈LIFO的行为

// fifolifo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <queue>
#include <stack>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    cout << "FIFO order: 
";
    queue<string> q;        //队列q
    q.push("Tom");
    q.push("Dick");
    q.push("Harry");

    stack<string> s;        //栈s
    while (q.size() > 0)
    {
        string name = q.front();
        q.pop();
        cout << name << "
";
        s.push(name);
    }
    cout << "LIFO order:
";
    
    while (s.size() > 0)
    {
        cout << s.top() << "
";
        s.pop();
    }
    system("pause");
    return 0;
}

原文地址:https://www.cnblogs.com/david-zhao/p/5087444.html