用两个栈来实现一个队列
1.
class Solution { public: void push(int node) { stack1.push(node); } int pop() {//删除队列前面元素 int result; if(stack2.empty())//栈可以这样看空不 size不好 { while(!stack1.empty()) { int cc= stack1.top(); stack2.push(cc); stack1.pop(); } } result = stack2.top(); stack2.pop(); return result; } private: stack<int> stack1; stack<int> stack2; };
讲解: