Exemplo n.º 1
0
        static void Main(string[] args)
        {
            stack st = new stack();

            while (true)
            {

                Console.Clear();

                Console.WriteLine("\nStack MENU(size -- 10)");

                Console.WriteLine("1. Add an element");

                Console.WriteLine("2. See the Top element.");

                Console.WriteLine("3. Remove top element.");

                Console.WriteLine("4. Display stack elements.");

                Console.WriteLine("5. Exit");

                Console.Write("Select your choice: ");

                int choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {

                    case 1:

                        Console.WriteLine("Enter an Element : ");

                        st.Push(Console.ReadLine());

                        break;

                    case 2: Console.WriteLine("Top element is: {0}", st.Peek());

                        break;

                    case 3: Console.WriteLine("Element removed: {0}", st.Pop());

                        break;

                    case 4: st.Display();

                        break;

                    case 5: System.Environment.Exit(1);

                        break;

                }

                Console.ReadKey();

            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            stack st = new stack();

            Console.WriteLine("Enter an Elements : ");
            st.Push(5);
            st.Push(9);
            st.Push(8);
            Console.WriteLine("Top element is: {0}", st.Peek());
            Console.WriteLine("Element removed: {0}", st.Pop());
            st.Display();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //A new stack variable is created
            stack st = new stack();

            //The programmer displays the menu of what you can do with the stack
            while (true)
            {
                Console.Clear();
                Console.WriteLine("\nStack MENU(size -- 10)");
                Console.WriteLine("1. Add an element");
                Console.WriteLine("2. See the Top element.");
                Console.WriteLine("3. Remove top element.");
                Console.WriteLine("4. Display stack elements.");
                Console.WriteLine("5. Exit");
                Console.Write("Select your choice: ");
                int choice = Convert.ToInt32(Console.ReadLine());

                //Switch statements used to reflect the options of the above menu
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter an Element : ");
                    st.Push(Console.ReadLine());
                    break;

                case 2:
                    Console.WriteLine("Top element is: {0}", st.Peek());
                    break;

                case 3:
                    Console.WriteLine("Element removed: {0}", st.Pop());
                    break;

                case 4:
                    st.Display();
                    break;

                case 5:
                    System.Environment.Exit(1);
                    break;
                }
                Console.ReadKey();
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            stack st = new stack();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("\nStack MENU");
                Console.WriteLine("1. Add an element");
                Console.WriteLine("2. Remove top element.");
                Console.WriteLine("3. Display stack elements.");
                Console.WriteLine("4. Reverse stack elements.");
                Console.WriteLine("5. Exit");
                Console.Write("Select your choice: ");
                int choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter an Element : ");
                    st.Push(Console.ReadLine());
                    break;


                case 2:
                    Console.WriteLine("Element removed: {0}", st.Pop());
                    break;

                case 3:
                    st.Display();
                    break;

                case 4:
                    Console.WriteLine("Enter an Element : ");
                    st.Reverse();
                    break;

                case 5:
                    System.Environment.Exit(1);
                    break;
                }
                Console.ReadKey();
            }
        }