
/**
 * LinkedQueue implaments the QueueADT interface
 * using Nodes containg Object data that are 
 * linked with a Node parameter.
 * 
 * @author Michael Rivers
 * @version 1.0
 */
public class LinkedQueue implements QueueADT
{
    // Parameters front and back identify
    // who is in front and back of the queue
    public Node front, back;

    /*
     * Default constructor sets parameters to null
     */
    public LinkedQueue()
    {
        front = null;
        back = null;
    }

    /*
     * Constructor takes Object data to start a queue
     */
    public LinkedQueue(Object data)
    {
        front = new Node(data);
        back = front;
    }
    
    /*
     * Constructor takes an int for no apparent reason
     */
    public LinkedQueue(int i)
    {
        front = null;
        back = null;
    }
    
    /*
     * push adds a node to the queue
     */
    public Object push(Object data)
    {
        if(data == null)
            return null;
        Node node = new Node(data);
        if(!isEmpty())
            back.setNext(node);
        back = node;
        if(isEmpty())
            front = node;
        return node.getData();
    }
    
    /*
     * pop takes a node from the front of the queue
     */
    public Object pop()
    {
        Node node = front;
        front = node.getNext();
        return node.getData();
    }
    
    /*
     * front returns the node in the front of the line
     */
    public Object front()
    {
        if(isEmpty())
            return null;
        return front.getData();
    }
    
    /*
     * back returns the node from the back of the queue
     */
    public Object back()
    {
        if(isEmpty())
            return null;
        return back.getData();
    }
    
    /*
     * isEmpty return true if the queue is empty
     * otherwise it returns false
     */
    public boolean isEmpty()
    {
        if(front == null)
            return true;
        return false;
    }
     
    /*
     * clear clears the queue
     */
    public void clear()
    {
        front = null;
        back = null;
    }
    
}

