注意使用一个栈存储从头到尾的数据,然后利用该栈输出数据,同时使用另外一个栈存储从尾到头的数据。
void push(int node) {
stack1.push(node);
}
int pop() {
if (stack2.empty())
{
while (!stack1.empty())
{
int a = stack1.top();
stack2.push(a);
stack1.pop();
}
}
int temp = stack2.top();
stack2.pop();
return temp;
}