static void Main(string[] args)
        {
            var stack = new StackInheritance();

            // create data to store in List
            // create data to store in List
            double[] numbers = { 1, 2, 3 };



            for (int i = 0; i < numbers.Length; i++)
            {
                stack.Push(numbers[i]);
            }

            Console.WriteLine("Get the stack using Push() method----");
            stack.Display();
            Console.WriteLine();

            Console.WriteLine("Get the first item of stack using Peek() method---");
            Console.WriteLine("The first item is " + stack.Peek());
            Console.WriteLine();

            Console.WriteLine("After using the Pop() method----");
            stack.Pop();
            stack.Display();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            StackInheritance stack = new StackInheritance();

            for (int i = 0; i < 5; ++i)
            {
                Console.Write("Enter a value: ");
                var userInput = Console.ReadLine();
                stack.Push(userInput);
                stack.Display();
            }

            try
            {
                while (true)
                {
                    object removedObject = stack.Pop();
                    Console.WriteLine(removedObject + " popped");
                    stack.Display();
                }
            }
            catch (EmptyListException emptyListException)
            {
                Console.Error.WriteLine(emptyListException);
            }

            // hold
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            StackInheritance stack    = new StackInheritance();
            Double           anDouble = 34567;

            // use method Push to add items to stack
            stack.Push(12);
            stack.Display();
            stack.Push(25);
            stack.Display();
            stack.Push(anDouble);
            stack.Display();
            stack.Push(35.25);
            stack.Display();
            Console.WriteLine("Top one is " + stack.Peek());


            // remove items from stack
            try
            {
                while (true)
                {
                    Double removedObject = stack.Pop();
                    Console.WriteLine($"{removedObject} popped");
                    stack.Display();
                }
            }
            catch (EmptyListException emptyListException)
            {
                // if exception occurs, write stack trace
                //Console.Error.WriteLine(emptyListException.StackTrace);
                Console.Error.WriteLine(emptyListException.Message);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            StackInheritance stack = new StackInheritance();

            Console.WriteLine("Stacking Fibonatti's numbers divided by 10");
            stack.Push(0.1);
            stack.Push(0.1);
            stack.Push(0.2);
            stack.Push(0.3);
            stack.Push(0.5);
            stack.Push(0.8);
            stack.Push(1.3);
            stack.Push(2.1);
            Console.WriteLine("First 8 Fibonatti's numbers divided by 10");
            stack.Display();
            Console.WriteLine("Popping 4");
            stack.Pop();
            stack.Pop();
            stack.Pop();
            stack.Pop();
            stack.Display();
            Console.WriteLine("Peeking the result..." + LinkedListLibrary.MyToString.ToString(stack.Peek()));
            Console.WriteLine("Popping 2 more...");
            stack.Pop();
            stack.Pop();
            Console.WriteLine("Showing the stack.");
            stack.Display();
        }
Beispiel #5
0
    public static void Main()
    {
        StackInheritance stack = new StackInheritance();

        stack.Push(24.8);
        stack.Display();
        stack.Push(84.64);
        stack.Display();
        stack.Push(334.442);
        stack.Display();
        stack.Push(354.1);
        stack.Display();
    }
    public static void test()
    {
        StackInheritance stack = new StackInheritance();

        stack.Push(1);
        Console.WriteLine(stack.Display());
        stack.Push(2);
        Console.WriteLine(stack.Display()); stack.Display();
        stack.Pop();
        Console.WriteLine(stack.Display());
        double peekValue = Convert.ToDouble(stack.Peek());

        Console.WriteLine("peek result: " + stack.Peek());
        Console.WriteLine(stack.Display());
        Console.ReadKey();
    }
    static void Main()
    {
        StackInheritance stack = new StackInheritance();

        // create objects to store in the stack
        double a = 25.02;
        double b = 20.35;
        double c = 34.56;
        double d = 65.25;

        //string aString = "hello";

        // use method Push to add items to stack
        stack.Push(a);
        stack.Display();
        stack.Push(b);
        stack.Display();
        stack.Push(c);
        stack.Display();
        stack.Push(d);
        stack.Display();
        var f = stack.peek();

        Console.WriteLine("\nTop element of the stack iS  " + f + "\n");


        // remove items from stack
        try
        {
            while (true)
            {
                double removedObject = stack.Pop();
                Console.WriteLine($"{removedObject} popped");
                stack.Display();
            }
        }
        catch (EmptyListException emptyListException)
        {
            // if exception occurs, write stack trace
            Console.Error.WriteLine(emptyListException.StackTrace);
        }
    }
    static void Main()
    {
        StackInheritance stack = new StackInheritance();

        // create objects to store in the stack
        bool   aBoolean   = true;
        char   aCharacter = '$';
        int    anInteger  = 34567;
        string aString    = "hello";

        // use method Push to add items to stack
        stack.Push(aBoolean);
        stack.Display();
        stack.Push(aCharacter);
        stack.Display();
        stack.Push(anInteger);
        //stack.Peek();
        stack.Display();
        stack.Push(aString);
        stack.Display();

        // remove items from stack
        try
        {
            while (true)
            {
                object removedObject = stack.Pop();
                Console.WriteLine($"{removedObject} popped");
                stack.Display();
            }
        }
        catch (EmptyListException emptyListException)
        {
            // if exception occurs, write stack trace
            Console.Error.WriteLine(emptyListException.StackTrace);
        }
    }
Beispiel #9
0
        static void Main(string[] args)
        {
            StackInheritance stack    = new StackInheritance();
            Double           anDouble = 34567;

            Console.WriteLine("-----Empty Stack-----");
            stack.Display();
            // use method Push to add items to stack
            Console.WriteLine("-----Adding first Item----");
            stack.Push(12);
            stack.Display();
            Console.WriteLine("-----Adding Second Item----");
            stack.Push(25);
            stack.Display();
            Console.WriteLine("-----Adding Third Item----");
            stack.Push(anDouble);
            stack.Display();
            Console.WriteLine("-----Adding Fourth Item----");
            stack.Push(35.25);
            stack.Display();
            Console.WriteLine("-----Peeking First Item-----");
            Console.WriteLine("Top item: " + stack.Peek());
            Console.WriteLine();


            // remove items from stack
            try
            {
                while (true)
                {
                    Console.WriteLine("----Removed Item-----");
                    Double removedObject = stack.Pop();
                    Console.WriteLine($"{removedObject} popped");
                    stack.Display();
                }
            }
            catch (EmptyListException emptyListException)
            {
                // if exception occurs, write stack trace
                //Console.Error.WriteLine(emptyListException.StackTrace);
                Console.Error.WriteLine(emptyListException.Message);
            }
        }
Beispiel #10
0
    static void Main()
    {
        StackInheritance stack = new StackInheritance();

        double aDouble_1 = .4;
        double aDouble_2 = 0.3;
        double aDouble_3 = 03.4;
        double aDouble_4 = 20.4;

        stack.Push(aDouble_1);
        stack.Push(aDouble_2);
        stack.Display();
        stack.Push(aDouble_3);
        stack.Display();
        stack.Push(aDouble_4);
        stack.Display();

        while (true)
        {
            Console.WriteLine("\nStack - Test");
            Console.WriteLine("--------------");
            Console.WriteLine("1. Push");
            Console.WriteLine("2. Peek");
            Console.WriteLine("3. Pop");
            Console.WriteLine("4. EXIT");

            int option = int.Parse(Console.ReadLine());

            switch (option)
            {
            case 1:
                Console.Write("Enter an Element : ");
                try
                {
                    string numberToPush = Console.ReadLine();
                    double number_1     = double.Parse(numberToPush);
                    stack.Push(number_1);
                }
                catch (EmptyListException emptyListException)
                {
                    Console.Error.WriteLine(emptyListException.StackTrace);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0} Exception caught.", ex);
                }
                stack.Display();
                break;

            case 2:
                Console.WriteLine("Enter an Element to Peek : ");
                try
                {
                    //string numberToPeek = Console.ReadLine();
                    //double number_2 = double.Parse(numberToPeek);
                    stack.Peek();
                }
                catch (EmptyListException emptyListException)
                {
                    Console.Error.WriteLine(emptyListException.StackTrace);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0} Exception caught.", ex);
                }
                stack.Display();
                break;

            case 3:
                Console.WriteLine("Test Pop : ");
                try
                {
                    object element = stack.Pop();
                    Console.WriteLine($"{element} popped");
                }
                catch (EmptyListException emptyListException)
                {
                    Console.Error.WriteLine(emptyListException.StackTrace);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0} Exception caught.", ex);
                }
                stack.Display();
                break;

            case 4:
                Environment.Exit(0);
                break;

            default:
                throw new ArgumentException("Value not supported :" + option);
            }
        }
    }
        static void Main(string[] args)
        {
            //ENVIRONMENT SETUP++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //create stack container
            StackInheritance stack = new StackInheritance();

            //create data values to be added to the stack
            double num1 = 23.42;
            double num2 = -923.11;
            double num3 = 0.0001;
            double num4 = 92323231;

            //TESTING PUSH+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            Console.WriteLine("PUSHING items onto the stack!");
            Console.WriteLine("---------------------------------------------------------------");
            try
            {
                Console.WriteLine($"PUSHING {num1} onto the stack.");
                stack.Push(num1);
                Console.WriteLine($"Currently, the top item in the stack is {stack.Peek()}");
                Console.WriteLine("Using List's Display method to see entire contents of the stack:");
                stack.Display();

                Console.WriteLine($"PUSHING {num2} onto the stack.");
                stack.Push(num2);
                Console.WriteLine($"Currently, the top item in the stack is {stack.Peek()}");
                Console.WriteLine("Using List's Display method to see entire contents of the stack:");
                stack.Display();

                Console.WriteLine($"PUSHING {num3} onto the stack.");
                stack.Push(num3);
                Console.WriteLine($"Currently, the top item in the stack is {stack.Peek()}");
                Console.WriteLine("Using List's Display method to see entire contents of the stack:");
                stack.Display();

                Console.WriteLine($"PUSHING {num4} onto the stack.");
                stack.Push(num4);
                Console.WriteLine($"Currently, the top item in the stack is {stack.Peek()}");
                Console.WriteLine("Using List's Display method to see entire contents of the stack:");
                stack.Display();
            }
            catch (EmptyListException e)
            {
                Console.WriteLine(e.Message);
            }


            //TESTING POP++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            Console.WriteLine("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
            Console.WriteLine("POPPING items from the stack!");
            Console.WriteLine("---------------------------------------------------------------");
            try
            {
                while (true)
                {
                    Console.WriteLine($"POPPING {stack.Pop()} from the stack.");
                    Console.WriteLine($"Currently, the top item in the stack is {stack.Peek()}");
                    Console.WriteLine("Using List's Display method to see entire contents of the stack:");
                    stack.Display();
                }
            }
            catch (EmptyListException e)
            {
                Console.WriteLine(e.Message);
            }

            //TESTING PEEK+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            Console.WriteLine("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
            Console.WriteLine("NOTE: Peek was used throughout this program to look at the top of the stack.");
        }