Esempio n. 1
0
        public void Stack()
        {
            //ObjectStack myStack = new ObjectStack();
            //myStack.Push(1);
            //myStack.Push(2);
            //myStack.Push(3);
            //while (myStack.Count > 0)
            //{
            //    Console.WriteLine("Peeking the next element: {0}", myStack.Peek());
            //    Console.WriteLine("Taking the next element: {0}", myStack.Pop());
            //}

            //Int Stack
            IntStack intStack = new IntStack();

            intStack.Push(1);
            intStack.Push(3123);
            intStack.Push(45);

            int intItem = intStack.Pop();

            //String Stack
            StringStack stringStack = new StringStack();

            stringStack.Push("farasat");
            stringStack.Push("aamir");
            stringStack.Push("noman");

            string strItem = stringStack.Pop();

            //Object Stack
            ObjectStack objectStack = new ObjectStack();

            objectStack.Push((object)1);
            objectStack.Push((object)13);
            objectStack.Push((object)45);

            object objectItem = (object)objectStack.Pop();

            //Templated Stack
            Stack <int> stack = new Stack <int>();

            stack.Push(1);
            stack.Push(13);
            stack.Push(45);

            int iItem = stack.Pop();

            Stack <string> strStack = new Stack <string>();

            strStack.Push("aamir");
            strStack.Push("farasat");
            strStack.Push("noman");

            string stItem = strStack.Pop();
        }
Esempio n. 2
0
        public void StackAsString()
        {
            StringStack myStack = new StringStack();

            myStack.Push("1");
            myStack.Push("2");
            myStack.Push("3");
            while (myStack.Count > 0)
            {
                Console.WriteLine("Peeking the next element: {0}", myStack.Peek());
                Console.WriteLine("Taking the next element: {0}", myStack.Pop());
            }
        }