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; };
讲解:
原文地址:https://www.cnblogs.com/cgy1012/p/11369991.html
时间: 2024-10-07 17:37:37