用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
using System.Collections.Generic;
class Solution
{
Stack stackPop=new Stack();
Stack stackPush=new Stack();
public void push(int node)
{
stackPush.Push(node);
}
public int pop()
{
while(stackPush.Count!=0)
stackPop.Push(stackPush.Pop());
int res=stackPop.Pop();
while(stackPop.Count!=0)
stackPush.Push(stackPop.Pop());
return res;
}
}