title: Circular Linked List Node Insertion Java
body: <p>I tried implementing the insert method for circular linked list. I think I had some success. </p>
  
  <p>Problem:
  When I display the list. The display method will loop because every next variable of the link is linked to a non-null node object. So head will never be a null object. From what I recall about singly linked list, head always point to the first node in the list or the first node with data inside of it.</p>
  
  <p>My conceptual understanding of circular linked list:
  From what I can understand circular linked is somewhat like a singly linked list but with a slight twist: the next variable of the tail object points to the head.</p>
  
  <p>I'm coding it like the diagram has presented provided by the source link. </p>
  
  <p>Source: <a href="http://sourcecodemania.com/circular-linked-lists/" rel="nofollow">http://sourcecodemania.com/circular-linked-lists/</a></p>
  
  <pre><code>public void insert(String data)
      {
          Link link = new Link(data);
  
          if(head == null)
          {
              head = link;
              tail= link;
          }
          else
          {
              tail.next = link;
              tail = link;
              tail.next = head;
  
          }
      }
  
  
  public void display()
      {
  
  
          // good implementation for display #2
          while(head != null)
          {
          //  System.out.println (head.data);
              head = head.next;
          }
      }
  </code></pre>