下面程序演示了队列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: \n"; 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 << "\n"; s.push(name); } cout << "LIFO order:\n"; while (s.size() > 0) { cout << s.top() << "\n"; s.pop(); } system("pause"); return 0; }
原文:http://www.cnblogs.com/david-zhao/p/5087444.html