class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
//if(stack1.empty()) return 0;
copy(stack2, stack1);
int res = stack2.top();
stack2.pop();
copy(stack1, stack2);
return res;
}
//将b的导入a中
void copy(stack<int> &a, stack<int> &b){
//if(a.empty() || b.empty()) return;
while(b.size()){
a.push(b.top());
b.pop();
}
}
private:
stack<int> stack1;
stack<int> stack2;
};
京公网安备 11010502036488号