title: Understanding the enqueue method for Linked List Queue
body: <p>Im having trouble understanding the code for the enqueue method for a linkedlist queue. I understand the dequeue(), isEmpty(), First() and size(). Firstly here is there LinearNode class to create the new node objects:</p>
  
  <pre><code>public class LinearNode&lt;T&gt; {
      private T element;
      private LinearNode&lt;T&gt; next;
  
      /**
       * Constructor: Creates an empty node.
       */
      public LinearNode() {
          next = null;
          element = null;
      }
  
      /**
       * Constructor: Creates a node storing the specified element.
       * @param elem  The specified element that is to be kept by this LinearNode.
       */
      public LinearNode(T elem) {
          next = null;
          element = elem;
      }
  
      /**
       *  Returns the node that follows this one.
       * @return  The node that follows this one.
       */
      public LinearNode&lt;T&gt; getNext() {
          return next;
      }
  
      /**
       *  Sets the node that follows this one.
       * @param node  The node which is to follow this one.
       */
      public void setNext(LinearNode&lt;T&gt; node) {
          next = node;
      }
  
      /**
       *  Returns the element stored in this node.
       * @return  The element that is kept within this node.
       */
      public T getElement() {
          return element;
      }
  
      /**
       *  Sets the element stored in this node.
       * @param elem  The element that is to be kept within this node.
       */
      public void setElement(T elem) {
          element = elem;
      }
  }
  </code></pre>
  
  <p>And here is the Enqueue method </p>
  
  <pre><code>public void enqueue(T element) {
      LinearNode&lt;T&gt; tmp = new LinearNode&lt;T&gt;(element);
      if (isEmpty()) {
          // set-up front to point to the new node
          front = tmp;
      } else {
          // add the node after the old tail node
          rear.setNext(tmp);
      }
      // update rear to point to the new node
      rear = tmp;
      count++; // increment size
  }
  </code></pre>
  
  <p>The part of the code im getting confused is <code>rear.setNext(tmp);</code> I mean shouldnt it be <code>temp.setNext(rear);</code> How can you use the method .setNext(); on the <code>LinearNode&lt;T&gt; rear;</code> when you havnt made new object called rear the only new object I can see made is called <code>temp</code> ??</p>
  
  <p>Edit
  Here the LinkQueue Class that contains the Enqueue method:</p>
  
  <pre><code>public class LinkedQueue&lt;T&gt; implements QueueADT&lt;T&gt; {
  private LinearNode&lt;T&gt; front; // front node of the queue
  private LinearNode&lt;T&gt; rear;  // rear node of the queue
  private int count;           // the current size of the queue
  
  /**
   * Constructor: Creates an empty Queue.
   */
  public LinkedQueue() { 
      count = 0;
      /* the following assignments are not actually necessary as references
       *  are initialised automatically to null, 
       *  but they are included for clarity.
       */
      front = null;
      rear = null;
  }
  </code></pre>