Пример #1
0
        //function for all stack operations
        static void StackOperation()
        {
            Stack stack = new Stack();
            int   choiceStack;

            do
            {
                Console.WriteLine();
                Console.WriteLine("Enter 1 to add a value in stack " +
                                  "\n2 to remove value " +
                                  "\n3 to show the stack " +
                                  "\n4 to get top value " +
                                  "\n5 to sort the stack" +
                                  "\n6 to Exit ");
                choiceStack = int.Parse(Console.ReadLine());
                switch (choiceStack)
                {
                case 1:
                    Console.WriteLine("Enter Elements");
                    int data = int.Parse(Console.ReadLine());
                    stack.Add(data);
                    Console.WriteLine("Data Added");
                    break;

                case 2: stack.Remove();
                    Console.WriteLine("Data removed");
                    break;

                case 3:
                    Console.Write("Stack contains :- ");
                    stack.Display();
                    Console.WriteLine();
                    break;

                case 4:
                    int top = stack.GetTopValue();
                    Console.WriteLine("Top of the stack is :- " + top);
                    Console.WriteLine();
                    break;

                case 5:
                    stack.Sort();
                    Console.WriteLine("Stack Sorted");
                    break;

                case 6:
                    break;

                default: Console.WriteLine("Invalid Entry");
                    break;
                }
            }while (choiceStack != 6);
        }