Ejemplo n.º 1
0
        /// <summary>
        /// Uses a second, temporary stack to emulate the action of Enqueueing a Node in a Queue
        /// via transferring data back and forth between the Stacks
        /// Adds the Node to the PseudoQueue
        /// </summary>
        /// <param name="node">Node to add to the Rear of the PseudoQueue</param>
        public void Enqueue(Node <T> node)
        {
            MyStack <T> StackTwo = new MyStack <T>();

            while (StackOne.Top != null)
            {
                Node <T> temp = StackOne.Pop();
                StackTwo.Push(temp);
            }

            StackOne.Push(node);

            while (StackTwo.Top != null)
            {
                Node <T> temp = StackTwo.Pop();
                StackOne.Push(temp);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses a second, temporary stack to emulate the action of Peeking a Node in a Queue
        /// via transferring data back and forth between the Stacks
        /// Does not add or remove any Nodes from the PseudoQueue
        /// </summary>
        /// <returns>Node at the Front of the PseudoQueue</returns>
        public Node <T> Peek()
        {
            Node <T>    returnTemp = null;
            MyStack <T> StackTwo   = new MyStack <T>();

            while (StackOne.Top != null)
            {
                Node <T> temp = StackOne.Pop();
                StackTwo.Push(temp);
            }

            returnTemp = StackTwo.Peek();

            while (StackTwo.Top != null)
            {
                Node <T> temp = StackTwo.Pop();
                StackOne.Push(temp);
            }

            return(returnTemp);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a Stack to store Nodes in
 /// </summary>
 public MyPseudoQueue()
 {
     StackOne = new MyStack <T>();
 }