Beispiel #1
0
        public void MultiplePush()
        {
            stack test = new stack();

            test.Push(5);
            test.Push(4);
            test.Push(3);
            Assert.Equal(3, test.Top.Value);
        }
Beispiel #2
0
        public void TestPeek()
        {
            stack S3 = new stack(10);

            S3.Push(1);
            S3.Push(2);
            S3.Push(3);
            Assert.AreEqual(3, S3.Peek());
        }
Beispiel #3
0
        public void TestPush()
        {
            stack S1 = new stack(15);

            S1.Push(1);
            S1.Push(2);
            S1.Push(3);
            Assert.AreEqual(3, S1.Count());
        }
Beispiel #4
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 #5
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);
        }
Beispiel #6
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 #7
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 #9
0
        public void PushtoStack()
        {
            stack test = new stack();

            test.Push(5);
            Assert.Equal(5, test.Top.Value);
        }
Beispiel #10
0
        public stack Reverse(stack input)
        {
            stack temp = new stack(input.StackSize);

            while (input.top >= 0)
            {
                temp.Push(input.Pop());
            }
            return(temp);
        }
Beispiel #11
0
        public void TestClear()
        {
            stack S5 = new stack(10);

            S5.Push(1);
            S5.Push(2);
            S5.Push(3);
            S5.Push(4);
            S5.Push(5);
            S5.Push(6);
            S5.Push(7);
            S5.Clear();
            Assert.AreEqual(0, S5.Count());
        }
Beispiel #12
0
        public void TestCount()
        {
            stack S4 = new stack(7);

            S4.Push(1);
            S4.Push(2);
            S4.Push(3);
            S4.Push(4);
            S4.Push(5);
            S4.Push(6);
            Assert.AreEqual(6, S4.Count());
        }
Beispiel #13
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 #14
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();
        }