Beispiel #1
0
        public void TestPop()
        {
            stack S2 = new stack(15);

            S2.Push(1);
            Assert.AreEqual(1, S2.Pop());

            S2.Push(2);
            Assert.AreEqual(2, S2.Pop());
        }
Beispiel #2
0
        public void EmptyTheStackAfterMultiplePops()
        {
            stack test = new stack();

            test.Push(5);
            test.Push(4);
            test.Push(3);
            object popOff  = test.Pop();
            object popOff2 = test.Pop();

            Assert.NotEqual(3, popOff);
        }
        static void Main(string[] args)
        {
            var stack = new stack();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            System.Console.WriteLine(stack.Pop());
            System.Console.WriteLine(stack.Pop());
            System.Console.WriteLine(stack.Pop());
        }
Beispiel #4
0
        public stack Reverse(stack input)
        {
            stack temp = new stack(input.StackSize);

            while (input.top >= 0)
            {
                temp.Push(input.Pop());
            }
            return(temp);
        }
Beispiel #5
0
        public void PopOffStack()
        {
            stack test = new stack();

            test.Push(4);
            test.Push(3);
            test.Push(2);
            object popOff = test.Pop();

            Assert.NotEqual(3, popOff);
        }
Beispiel #6
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();
        }
Beispiel #7
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();
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("the days are :-");

            Stack days = new stack();

            days.Push("sunday");
            days.Push("monday");
            days.Push("tuesday");
            days.Push("wednesday");
            days.Push("thusday");
            days.Push("friday");
            days.Push("saturday");
            while (days.Count > 0)
            {
                string day = days.Pop().ToString();
                Console.WriteLine(day);
            }
            Console.ReadKey();
        }