Beispiel #1
0
        static void Main(string[] args)
        {
            int   choice;
            Stack obj = new Stack();

            do
            {
                Console.WriteLine(" Stack Main Menu\n\n1.Insert \n2.Remove \n3.Display \n4. to exit\nEnter Your Choice");
                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case 1:
                    obj.Push();
                    break;

                case 2:
                    obj.Pop();
                    break;

                case 3:
                    obj.Display();
                    break;
                }
            } while (choice != 4);
        }
        static void Main(string[] args)
        {
            Stack stack = new Stack();

            stack.Push("Ivo");
            stack.Push("Ana");
            stack.Push("Bob");
            stack.Push("Iva");
            stack.Push("Kim");
            stack.Display();
            try
            {
                for (int i = 0; i < 6; i++)
                {
                    stack.Pop();
                    stack.Display();
                }
            }
            catch (Exception x)
            {
                Console.WriteLine(x.Message);
            }
            stack.Display();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            bool exit  = false;
            var  stack = new Stack(10);

            while (!exit)
            {
                Console.WriteLine("Choose an operation:");
                Console.WriteLine("1. Push");
                Console.WriteLine("2. Pop");
                Console.WriteLine("3. Display Stack");
                int num = Convert.ToInt32(Console.ReadLine());
                int n;
                switch (num)
                {
                case 1:
                    Console.Write("Insert a number:");
                    var line = Console.ReadLine();
                    if (int.TryParse(line, out n))
                    {
                        stack.push(n);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Input........");
                    }
                    break;

                case 2:
                    n = stack.Pop();
                    Console.WriteLine($"Deleted data:{n}");
                    break;

                case 3:
                    stack.Display();
                    break;

                default:
                    Console.WriteLine("Exiting........");
                    exit = true;
                    break;
                }
                Console.WriteLine();
            }
        }