Exemple #1
0
        public void TestPeek()
        {
            Stack1 S = new Stack1();

            S.Push("1");
            S.Push("2");
            S.Push("3");
            Assert.AreEqual("3", S.Peek());
            Assert.AreEqual("2", S.Peek());
        }
 /// <summary>
 /// This method removes the node at the "front" of the queue; which is at the bottom of stack1.
 /// </summary>
 /// <returns>This is the node at the bottom of stack 1</returns>
 public Node Dequeue()
 {
     if (Stack2.Peek() == null)
     {
         while (Stack1.Peek().Next != null)
         {
             Stack2.Push(Stack1.Pop());
         }
         Stack2.Push(Stack1.Pop());
     }
     return(Stack2.Pop());
 }
Exemple #3
0
        /// <summary>
        /// Removes a node from the queue
        /// </summary>
        /// <returns>returns the node that was dequeued</returns>
        public Node Dequeue()
        {
            if (Stack2.Peek() == null)
            {
                return(null);
            }

            while (Stack2.Peek().Next != null)
            {
                Stack1.Push(Stack2.Pop());
            }

            Node temp = Stack2.Pop();

            while (Stack1.Peek() != null)
            {
                Stack2.Push(Stack1.Pop());
            }

            return(temp);
        }