Beispiel #1
0
        static void Main()
        {
            int numberOfElements;

            Console.WriteLine("Program exhibiting functionality of Stack\n\n");
            Console.WriteLine("How big do you want the Stack? = \t");
            if (int.TryParse(Console.ReadLine(), out numberOfElements))
            {
                Stack stackObject = new Stack(numberOfElements);
                int   choice;
                do
                {
                    Console.WriteLine(
                        "What would you like to do? \n1. Display Stack \n2. Add Element To Stack \n3. Remove Element from Stack \n4. Exit");
                    int.TryParse(Console.ReadLine(), out choice);
                    switch (choice)
                    {
                    case 1:
                    {
                        stackObject.DisplayStackContent();
                        break;
                    }

                    case 2:
                    {
                        Console.WriteLine("Please Enter The Element = \t");
                        string input = Console.ReadLine();

                        stackObject.AddElementToStack(input);
                        break;
                    }

                    case 3:
                    {
                        stackObject.DeleteElementFromStack();
                        break;
                    }

                    case 4:
                    {
                        Console.WriteLine("Goodbye!");
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Invalid Choice!");
                        break;
                    }
                    }
                } while (choice != 4);
            }
            else
            {
                Console.WriteLine("Invalid Input. Please Try Again.");
            }
        }