Esempio n. 1
0
        private static void TestMyPQStack()
        {
            MyPQStack <int> stack = new MyPQStack <int>();

            // test empty stack
            Console.WriteLine(stack.Size() == 0);

            // test push and peek
            stack.Push(5);
            Console.WriteLine(stack.Size() == 1);
            Console.WriteLine(stack.Peek() == 5);
            stack.Push(2);
            Console.WriteLine(stack.Size() == 2);
            Console.WriteLine(stack.Peek() == 2);
            stack.Push(9);
            Console.WriteLine(stack.Size() == 3);
            Console.WriteLine(stack.Peek() == 9);
            // duplicate items not ignored
            stack.Push(3);
            Console.WriteLine(stack.Size() == 4);
            Console.WriteLine(stack.Peek() == 3);
            stack.Push(5);
            Console.WriteLine(stack.Size() == 5);
            Console.WriteLine(stack.Peek() == 5);

            // test pop
            int[] expected = { 5, 3, 9, 2, 5 };
            for (int i = 0, size = stack.Size(); i < size; i++)
            {
                Console.WriteLine(stack.Pop().Equals(expected[i]));
            }
        }
Esempio n. 2
0
 /* Destructively transfer stack1 items to stack2 in reverse order */
 private void FlipStack(MyPQStack <T> stack1, MyPQStack <T> stack2)
 {
     for (int i = 0, numItems = stack1.Size(); i < numItems; i++)
     {
         stack2.Push(stack1.Pop());
     }
 }
Esempio n. 3
0
 public void Enqueue(T item)
 {
     stack.Push(item);
     size++;
 }