剑指Offer6
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6?tpId=13&tqId=11158&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github
题目
思路
Code
class Solution { public: void push(int node) { stack1.push(node); } int pop() { if(stack2.empty()) //注意 ---只有当栈2为空时才能进行压入操作 { while(!stack1.empty()) //将栈1的元素全部压入栈2 { stack2.push(stack1.top()); stack1.pop(); } } int node = stack2.top(); stack2.pop(); return node; } private: stack<int> stack1; stack<int> stack2; };