设计一个队列,实现GetMin()函数

C# codes as below:

class Queue
{
private int min;

public int GetMin()
{
return min;
}

Stack<int> container = new Stack<int>();
Stack<int> container2 = new Stack<int>();

public int Pop()
{
return container2.Pop();
}

public void Push(int value)
{
if (value < min)
min = value;
while (container2.Count != 0)
container.Push(container2.Pop());
container2.Push(value);
while (container.Count != 0)
container2.Push(container.Pop());
}

}

你可能感兴趣的:(get)