public int Dequeue() { if (_stack1.Count == 0 && _stack2.Count == 0) { throw new InvalidOperationException(); } if (_stack2.Count == 0) { while (_stack1.Count > 0) { _stack2.Push(_stack1.Pop()); } } return(_stack2.Pop()); }
//TestFile("01"); //TestFile("02"); public static void MainTest(string[] args) { int q = StdIn.ReadInt(); StackWithMax stack = new StackWithMax(); for (int i = 0; i < q; i++) { string op = StdIn.ReadString(); if (op.Equals("push")) { stack.Push(StdIn.ReadInt()); } if (op.Equals("pop")) { stack.Pop(); } if (op.Equals("max")) { Console.WriteLine(stack.Max()); } } }
public void Enqueue(int item) { _stack1.Push(item); }