static void Main(string[] args) { StackWithMax stack = new StackWithMax(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; ++i) { string[] buf = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (buf[0] == "push") { stack.Push(int.Parse(buf[1])); } if (buf[0] == "pop") { stack.Pop(); } if (buf[0] == "max") { Console.WriteLine(stack.Max()); } } Console.ReadKey(); }
public QueueWithMax() { this.LStack = new StackWithMax(); this.RStack = new StackWithMax(); }