返回列表 發帖

queue & stack 練習

本帖最後由 tonyh 於 2023-11-24 21:11 編輯


  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. queue<int> q;
  4. stack<int> s;
  5. int main()
  6. {
  7.     q.push(1);
  8.     q.push(2);
  9.     q.push(3);
  10.     q.push(4);
  11.     q.push(5);

  12.     s.push(1);
  13.     s.push(2);
  14.     s.push(3);
  15.     s.push(4);
  16.     s.push(5);
  17.     s.pop();
  18.     s.pop();
  19.     s.pop();
  20.     s.push(5);
  21.     s.push(4);
  22.     s.push(3);

  23.     while(!q.empty())
  24.     {
  25.         cout<<q.front()<<" ";
  26.         q.pop();
  27.     }
  28.     cout<<endl<<"-------"<<endl;

  29.     while(!s.empty())
  30.     {
  31.         cout<<s.top()<<" ";
  32.         s.pop();
  33.     }
  34.     return 0;
  35. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

返回列表