示例#1
0
            public int Dequeue()
            {
                if (_out.IsEmpty())
                {
                    while (!_in.IsEmpty())
                    {
                        var el = _in.Pop();
                        _out.Push(el);
                    }
                }

                return(_out.Pop());
            }
示例#2
0
        public void StackWithMin()
        {
            StackWithMin stack = new StackWithMin();

            stack.Push(1);
            stack.Push(3);

            Assert.Equal(1, stack.Min);

            stack.Push(0);
            Assert.Equal(0, stack.Min);

            stack.Pop();
            Assert.Equal(1, stack.Min);
        }
示例#3
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());
            }
        }