/**
 * A Queue (of Object objects)
 *
 * This implementation uses linked memory
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Queue
{
    private int         size;    
    private Node        back, front;


    /**
     * Construct a new (empty) Queue
     */
    public Queue()
    {
        front = null;
        size = 0;        
    }



    /**
     * Pop an Object off of the front of this Queue
     *
     * @return  The Object at the front of this Queue
     */
    public Object pop()
    {
        Object  value;


        if (front != null) 
        {
            value = front.value;
            front = front.next;
            size--;            
        } 
        else
        {
            value = null;
        }

        return value;
    }


    /**
     * Push an Object onto the back of this Queue
     *
     * @param last   The Object to push
     */
    public void push(Object last)
    {
        Node temp;

        temp = new Node();
        temp.value = last;
        temp.next = null;

        size++;        

        if (front == null) 
        {
            front = temp;
        }
        else
        {
            back.next = temp;
        }

        back = temp;
    }


    /**
     * Return the number of elements currently
     * in this Queue
     */
    public int size()
    {
       return size;       
    }
    
}
