Beispiel #1
0
        public int Max()
        {
            if (_stack1.Count == 0 && _stack2.Count == 0)
            {
                throw new InvalidOperationException();
            }

            if (_stack1.Count != 0 && _stack2.Count != 0)
            {
                return(Math.Max(_stack1.Max(), _stack2.Max()));
            }
            if (_stack1.Count != 0)
            {
                return(_stack1.Max());
            }

            return(_stack2.Max());
        }
Beispiel #2
0
        //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());
                }
            }
        }