剑指 offer 练习题 利用两个栈来模拟一个队列


class Solution
{
public:
    void push(int node) {
        stack1.push(node);
    }

    int pop() {
        int temp;
        while(stack2.empty()){
              while(!stack1.empty()){
                  temp = stack1.top();
                  stack1.pop();
                  stack2.push(temp);
              }
        }
        temp = stack2.top();
        stack2.pop();
        return temp;
       
        
    }

private:
    stack<int> stack1;
    stack<int> stack2;
};

发布了95 篇原创文章 · 获赞 8 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/ttomchy/article/details/104590929
今日推荐