Exemple #1
0
        /*
         * Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
         * push(x) -- Push element x onto stack.
         * pop() -- Removes the element on top of the stack.
         * top() -- Get the top element.
         * getMin() -- Retrieve the minimum element in the stack.
         *
         * Example:
         * MinStack minStack = new MinStack();
         * minStack.push(-2);
         * minStack.push(0);
         * minStack.push(-3);
         * minStack.getMin();   --> Returns -3.
         * minStack.pop();
         * minStack.top();      --> Returns 0.
         * minStack.getMin();   --> Returns -2.
         *
         */
        static void Main(string[] args)
        {
            var minStack = new MinStack();

            minStack.Push(-2);
            minStack.Push(0);
            minStack.Push(-3);
            minStack.Pop();
            minStack.Pop();
            minStack.Pop();
        }
        static void Main(string[] args)
        {
            MinStack obj = new MinStack();

            obj.Push(-2);
            obj.Push(0);
            obj.Push(-3);
            Console.WriteLine(obj.GetMin()); //-3
            obj.Pop();
            Console.WriteLine(obj.Top());    // 0
            Console.WriteLine(obj.GetMin()); // -2
        }
        static void Main(string[] args)
        {
            MinStack S = new MinStack();

            S.Push(-2);
            S.Push(0);
            S.GetMin();
            S.Push(-3);
            S.GetMin();
            S.Pop();
            S.GetMin();
            S.Top();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            MinStack minStack = new MinStack();

            minStack.Push(-2);
            minStack.Push(0);
            minStack.Push(-3);
            Console.WriteLine(minStack.GetMin()); //--> Returns - 3.
            minStack.Pop();
            Console.WriteLine(minStack.Top());    //--> Returns 0.
            Console.WriteLine(minStack.GetMin()); //--> Returns - 2.
            Console.ReadKey();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var minStack = new MinStack();

            minStack.Push(5);
            minStack.Push(2);
            minStack.Push(12);
            minStack.Push(1);

            Console.WriteLine(minStack.GetMin());
            minStack.Pop();
            minStack.Pop();
            Console.WriteLine(minStack.GetMin());
            Console.ReadLine();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            MinStack obj = new MinStack();

            obj.Push(x);
            obj.Pop();
            int param_3 = obj.Top();
            int param_4 = obj.GetMin();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            MinStack minstack = new MinStack();
            int      min0     = minstack.GetMin();

            minstack.Push(2);
            minstack.Push(0);
            minstack.Push(3);
            minstack.Push(0);
            int min1 = minstack.GetMin();

            minstack.Pop();
            int min2 = minstack.GetMin();

            minstack.Pop();
            int min3 = minstack.GetMin();

            minstack.Pop();
            int min4 = minstack.GetMin();
            int top  = minstack.Top();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            MinStack obj = new MinStack();

            obj.Push(2147483646);
            obj.Push(2147483646);
            obj.Push(2147483647);
            Console.WriteLine(obj.Top());
            obj.Pop();
            Console.WriteLine(obj.GetMin());
            obj.Pop();
            Console.WriteLine(obj.GetMin());
            obj.Pop();
            obj.Push(2147483647);
            Console.WriteLine(obj.Top());
            Console.WriteLine(obj.GetMin());
            obj.Push(-2147483648);
            Console.WriteLine(obj.Top());
            Console.WriteLine(obj.GetMin());
            obj.Pop();
            Console.WriteLine(obj.GetMin());
            Console.ReadLine();
        }
Exemple #9
0
		public static void Main (string[] args)
		{
			MinStack tStack = new MinStack ();
			tStack.Push (3);
			tStack.Push (7);
			tStack.Push (2);
			tStack.Push (6);
			tStack.Push (19);
			tStack.Push (1);
			tStack.Push (13);
			Console.WriteLine (tStack.Top ());
			Console.WriteLine (tStack.GetMin ());
			tStack.Pop ();
			tStack.Pop ();
			Console.WriteLine (tStack.Top ());
			Console.WriteLine (tStack.GetMin ());
		}
        public static void Main(string[] args)
        {
            MinStack tStack = new MinStack();

            tStack.Push(3);
            tStack.Push(7);
            tStack.Push(2);
            tStack.Push(6);
            tStack.Push(19);
            tStack.Push(1);
            tStack.Push(13);
            Console.WriteLine(tStack.Top());
            Console.WriteLine(tStack.GetMin());
            tStack.Pop();
            tStack.Pop();
            Console.WriteLine(tStack.Top());
            Console.WriteLine(tStack.GetMin());
        }