示例#1
0
        static void Main(string[] args)
        {
            stack b = new stack();

            b.push(new customer("ofir", "levi", 1234.5));
            b.push(new customer("ron", "buch", 45679.5));
            b.push(new customer("tomer", "lerner", 9513.45));
            b.push(new customer("hai", "eliasy", 7456.2));
            b.push(new customer("yaakov", "ellyhasov", 5613.5));
            b.show();
            b.Peek();
            b.Pop();
            Console.WriteLine("******************\none customer has been deleted\n******************");
            b.show();
            b.Pop();
            Console.WriteLine("******************\none customer has been deleted\n******************");
            b.show();
            b.Pop();
            Console.WriteLine("******************\none customer has been deleted\n******************");
            b.show();
            b.Pop();
            Console.WriteLine("******************\none customer has been deleted\n******************");
            b.show();
            b.Pop();
            Console.WriteLine("******************\none customer has been deleted\n******************");
            b.show();
            b.Pop();
            b.show();
        }
示例#2
0
        public void TestPeek()
        {
            stack S3 = new stack(10);

            S3.Push(1);
            S3.Push(2);
            S3.Push(3);
            Assert.AreEqual(3, S3.Peek());
        }
示例#3
0
        public void Peek()
        {
            stack test = new stack();

            test.Push(5);
            test.Push(4);
            test.Push(3);
            object peeking = test.Peek();

            Assert.Equal(3, peeking);
        }
示例#4
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. Reverse stack elements.");
                Console.WriteLine("6. 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:
                    st = st.Reverse(st);
                    st.Display();
                    break;

                case 6: System.Environment.Exit(1);
                    break;
                }

                Console.ReadKey();
            }
        }