<ruby id="xh9j9"></ruby>

<th id="xh9j9"></th>

    1. <rp id="xh9j9"><object id="xh9j9"></object></rp>
      <rp id="xh9j9"></rp>

        首頁 > 編程學習 > 232.implement-queue-using-stacks 用棧實現隊列

        232.implement-queue-using-stacks 用棧實現隊列

        發布時間:8/15/2022 9:30:14 PM

        stOut為空時,將stIn中所有元素pushstOut

        #include <stack>
        using std::stack;
        class MyQueue {
          public:
            stack<int> stIn;
            stack<int> stOut;
            MyQueue() {
            }
        
            void push(int x) {
                stIn.push(x);
            }
        
            int pop() {
                if (stOut.empty()) {
                    while (!stIn.empty()) {
                        stOut.push(stIn.top());
                        stIn.pop();
                    }
                }
                int result = stOut.top();
                stOut.pop();
                return result;
            }
        
            int peek() {
                int res = this->pop();
                stOut.push(res);
                return res;
            }
        
            bool empty() {
                return stIn.empty() && stOut.empty();
            }
        };
        
        Copyright ? 2010-2022 wtld.cn 版權所有 |關于我們| 聯系方式
        日本精品人妻

        <ruby id="xh9j9"></ruby>

        <th id="xh9j9"></th>

        1. <rp id="xh9j9"><object id="xh9j9"></object></rp>
          <rp id="xh9j9"></rp>