public:void push(int node) {stack1.push(node);}int pop() {if(stack2.empty()){while(!stack1.empty()){stack2.push(stack1.top());stack1.pop();}}int val = stack2.top();stack2.pop();return val;}private:stack<int> stack1;stack<int> stack2;
引申题
用两个队列实现一个栈。
先将a、b、c都压入queue1
需要弹出时,将a、b压入queue2,弹出c
