用两个栈实现队列
class Solution { public: void push(int node) { stack1.push(node); } int pop() { int res = 0; if(!stack2.empty()) { res = stack2.top(); stack2.pop(); return res; } while(!stack1.empty()) { int tmp = stack1.top(); stack1.pop(); stack2.push(tmp); } res = stack2.top(); stack2.pop(); return res; } private: stack<int> stack1; //进入栈 stack<int> stack2; //辅助栈 };