c07p361.txt

来自「Data Abstraction & Problem Solving with 」· 文本 代码 · 共 46 行

TXT
46
字号
#include <iostream>#include <list>#include <queue>#include <stack>using namespace std;int main(){   list<int> myList;  // create an empty list   list<int>::iterator i = myList.begin();   for (int j = 1; j < 5; j++)   {  i = myList.insert(i, j);      i++;   }  // end for   cout << "myList:  ";   i = myList.begin();   while (i != myList.end())   {  cout << *i << " ";      i++;   }  // end while   cout << endl;   // assumes the front of the list is the front of the   // queue   queue<int, list<int> > myQueue(myList);   // assumes the back of the list is the top of the stack   stack<int, list<int> > myStack(myList);   cout << "myQueue: ";   while (!myQueue.empty())   {  cout << myQueue.front() << " ";      myQueue.pop();   }  // end while   cout << endl;   cout << "myStack: ";   while (!myStack.empty())   {  cout << myStack.top() << " ";      myStack.pop();   }  // end while   cout << endl;   return 0;}  // end main

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?