示例#1
0
文件: Q03_2.cs 项目: zs9912/ctci
        public void Run()
        {
            StackWithMin  stack  = new StackWithMin();
            StackWithMin2 stack2 = new StackWithMin2();

            for (int i = 1; i <= 10; i++)
            {
                int value = AssortedMethods.RandomIntInRange(0, 100);
                stack.Push2(value);
                stack2.Push2(value);
                Console.Write(value + ", ");
            }
            Console.WriteLine('\n');
            for (int i = 1; i <= 10; i++)
            {
                Console.WriteLine("Popped " + stack.Pop().Value + ", " + stack2.Pop2());
                Console.WriteLine("New min is " + stack.Min() + ", " + stack2.Min());
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            StackWithMin stack = new StackWithMin();
            stack.push(5);
            stack.push(6);
            stack.push(3);
            stack.push(7);
            Console.WriteLine(stack.Min());
            stack.pop();
            stack.pop();
            Console.WriteLine(stack.Min());

            StackWithMin2 stack2 = new StackWithMin2();
            stack2.push(5);
            stack2.push(6);
            stack2.push(3);
            stack2.push(7);
            Console.WriteLine(stack2.Min());
            stack2.pop();
            stack2.pop();
            Console.WriteLine(stack2.Min());
        }