标签:两个栈 int else 用两个栈 实现 while node off pop
class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
if(stack1.empty() && stack2.empty()){
return -1;
}
if(!stack2.empty()){
stack2.pop();
}
else{
while(!stack1.empty()){
stack2.push(stack1.top());
stack1.pop();
}
}
return stack2.top();
}
private:
stack<int> stack1;
stack<int> stack2;
};
标签:两个栈 int else 用两个栈 实现 while node off pop
原文地址:https://www.cnblogs.com/theodoric008/p/9513651.html