/**
*  This class shows an implementation of the queue abstract data type (ADT)
*  as an linked list.  It contains an inner class Node.
*  It will enqueue an element if the queue 
*  is not full; dequeue an element if the queue is not empty; test the queue
*  for emptyness and fullness; and it will return the value stored in the
*  element at the end of the list
*
*/

public class QueueAsLinkedList
{

    private  Node myLLqueue;
	 
	 
	 /** 
	 * default constructor 
	 *
	 */
	 public QueueAsLinkedList ()
	 {
	    myLLqueue = null; // set queue to empty
	 }
	 
	 /** 
	 *
	 *  determines whether queue is empty
	 *
	 *  @return a boolean true if it is empty, false otherwise
	 */
	 public boolean isEmpty()
	 {  
	     boolean returnValue;
		  
		  returnValue = false;  // assuming not empty 
	     if (myLLqueue == null ) // is empty
		    returnValue = true;
		  
		  return returnValue;
	 }
		 
	  /**
	  *  tells whether queue is full - always returns false
	  * 
	  *  @return boolean always false
	  */
	  public boolean isFull()
	  {
	     return false;
	  }
	  
	  	  
	  /**
	  *  first method lets you see the value first item
	  *  in the queue if there is one. Otherwise it says
	  *  queue is empty
	  *
	  *  @return  first value in queue as a String
	  * 
	  */
	  public String first ()
	  {
	     String name;

	     if (this.isEmpty()) // return message instead of value
		     name = " empty queue ";
		  else
		     name = " " + myLLqueue.customerName; 
		  
		  return name;
      }		  
	 
	    
	  /**
	  *  enQueue method adds a given value to the end of the queue
	  *  if the queue is not full.  Otherwise it does nothing
	  * 
	  *  @param value to be added to the queue
	  */
     public void enqueue (Customer cName)
	  {  
	      Node newNode, current;
			boolean added = false;

			newNode = new Node(cName);  // create a new customer node
			
			if (this.isEmpty()) // if list empty, node is first
			   myLLqueue = newNode;
			else  // node needs to be at end
			{  
            current = myLLqueue; // point current to head
				while (!added) // haven't added new Node
				{ 
				 if (current.next == null) // found where to add
				 {
				   current.next = newNode;
					added = true;   // done!
				 }
				 else   // keep looking for where to add
				 {
				   current = current.next;
				 }
	         }  // end while
			} // end else not first node	
		} // end enqueue	
		
		
        /**
	  *  deQueue method removes the first item in the queue
	  *  if there is a first item.  Otherwise it does nothing
	  *
	  */
	  public void dequeue()
	  {
	     if (this.isEmpty())// don't try to delete from empty queue
		  {
		    // do nothing
		  }
		  else  // remove the head of the list
	     {
		     myLLqueue = myLLqueue.next;
		  }
	} // end dequeue  
		  
	  private class Node 
	  {
	      public Customer customerName;
			public Node next;
			
		/**
		*
		* default constructor
		* 
		*/
		public Node()
		{
		   customerName = null;
			next = null;
      }
		
			
	   /**
		*  explicit value constructor
		*
		*/
		public Node(Customer name)
		{
		   this.customerName = name;
			next = null;
		}	  
	} // end private class Node			  
} // end QueueAsLinkedList