Example #1
0
        public static void Main(string[] args)
        {
            var stack = new ArrayStack <int>();

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

            stack.Pop();
            var array = stack.ToArray();

            Console.WriteLine(stack.Peek());
        }
Example #2
0
        static void Main(string[] args)
        {
            //Create a Random Number Generator
            Random num = new Random();

            //Create an ArrayList
            ArrayList myStack = new ArrayList();

            //Create a Array stack instance
            ArrayStack theStack = new ArrayStack(myStack, 10);
            
            WriteLine("Try To Pop An Empty Stack");
            theStack.Pop();

            //Fill the stack
            WriteLine("\nFill The Stack With Values");
            for (int i = 0; i < theStack.Capacity; i++)
            {
                theStack.Push(num.Next(0, 10));
            }//End for loop

            //Print the stack for comparison
            PrintStack(theStack);
            
            //Try out the peek method
            WriteLine($"\nPeek Method Returned: {theStack.Peek().ToString()}");

            //Try to push past capacity
            WriteLine("\nTry To Push Over Capacity");
            theStack.Push(22);

            //Tryout the pop method
            WriteLine($"\nPop Method Removed: {theStack.Peek()} From The Stack");
            theStack.Pop();
            WriteLine($"\nPop Method Removed: {theStack.Peek()} From The Stack");
            theStack.Pop();

            //Print for comparison
            PrintStack(theStack);

            //Try to push again
            WriteLine("\nPushing Value '22' To The Stack");
            theStack.Push(22);

            //Try to push again
            WriteLine("\nPushing Value '33' To The Stack");
            theStack.Push(33);

            //Try to push again
            WriteLine("\nPushing Value '44' To The Stack");
            theStack.Push(44);

            //Print for comparison
            PrintStack(theStack);

            //Try out the peek method
            WriteLine($"\nPeek Method Returned: {theStack.Peek().ToString()}");

            //Readkey to stop the program
            ReadKey();
        }