示例#1
0
        static void Main(string[] args)
        {
            StackL <string> myStack = new StackL <string>();

            myStack.Push("Hello");
            myStack.Push("there");
            myStack.Push("friend");

            Console.WriteLine(myStack.Peek());



            Console.WriteLine(myStack.Pop());
            Console.WriteLine(myStack.Count);

            Console.WriteLine(myStack.Pop());
            Console.WriteLine(myStack.Count);

            Console.WriteLine(myStack.Pop());

            //throw
            //Console.WriteLine(myStack.Pop());

            Console.WriteLine(myStack.Count);
        }
示例#2
0
        static void Main(string[] args)
        {
            int choice, x;

            StackL stack = new StackL();

            while (true)
            {
                Console.WriteLine("1. Push element onto stack");
                Console.WriteLine("2. Pop an element off stack");
                Console.WriteLine("3. Display the top element");
                Console.WriteLine("4. Display all stack elements");
                Console.WriteLine("5. Display stack size");
                Console.WriteLine("6. Quit");

                Console.WriteLine("Enter your choice: ");
                choice = Convert.ToInt32(Console.ReadLine());

                if (choice == 6)
                {
                    break;
                }
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter element to be pushed: ");
                    x = Convert.ToInt32(Console.ReadLine());
                    stack.Push(x);
                    break;

                case 2:
                    x = stack.Pop();
                    Console.WriteLine("Popped element is:  " + x);
                    break;

                case 3:
                    Console.WriteLine("Element at the top is:  " + stack.Peek());
                    break;

                case 4:
                    stack.Display();
                    break;

                case 5:
                    Console.WriteLine("Sixe of stack is:  " + stack.Size());
                    break;

                case 6:
                    Console.WriteLine("Wrong choice!");
                    break;
                }
                Console.WriteLine("");
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            int choice, x;

            StackL st = new StackL();

            while (true)
            {
                Console.WriteLine("1.Push an element on th stack ");
                Console.WriteLine("2.Pop an element from the stack ");
                Console.WriteLine("3.Display the top element ");
                Console.WriteLine("4.Display all the elements ");
                Console.WriteLine("5.Display size of the stack ");
                Console.WriteLine("6.Quit");
                Console.Write("Enter your choice ");
                choice = Convert.ToInt32(Console.ReadLine());

                if (choice == 6)
                {
                    break;
                }
                switch (choice)
                {
                case 1:
                    Console.Write("Enter the element to be pushed ");
                    x = Convert.ToInt32(Console.ReadLine());
                    st.Push(x);
                    break;

                case 2:
                    x = st.Pop();
                    Console.WriteLine("Popped element is : " + x);
                    break;

                case 3:
                    Console.WriteLine("Element at the top is " + st.Peek());
                    break;

                case 4:
                    st.Display();
                    break;

                case 5:
                    Console.WriteLine("Size of stack " + st.Size());
                    break;

                default:
                    Console.WriteLine("Wrong choice ");
                    break;
                }
                Console.WriteLine("");
            }
        }
示例#4
0
        static void Main(String[] args)
        {
            int    choice, x;
            StackL st = new StackL();

            while (true)
            {
                Console.WriteLine("1.push an element to the stack");
                Console.WriteLine("2.pop an element to the stack");
                Console.WriteLine("3.Display the top element");
                Console.WriteLine("4.Display all stack elements");
                Console.WriteLine("5.Display size of the stack");
                Console.WriteLine("6.Quit");
                Console.Write("enter your choise : ");
                choice = Convert.ToInt32(Console.ReadLine());
                if (choice == 6)
                {
                    break;
                }
                switch (choice)
                {
                case 1:
                    Console.WriteLine("enter an element to push");
                    x = Convert.ToInt32(Console.ReadLine());
                    st.Push(x);
                    break;

                case 2:
                    x = st.Pop();
                    Console.WriteLine("popped element is " + x);
                    break;

                case 3:
                    Console.WriteLine("element at the top is " + st.Peek());
                    break;

                case 4:
                    st.Display();
                    break;

                case 5:
                    Console.WriteLine("size of stack is" + st.Size());
                    break;

                default:
                    Console.WriteLine("wrong choice");
                    break;
                }
                Console.WriteLine(" ");
            }
        }