title: adding at the end of a singly-linked list in constant time
body: <p>I'm trying to write a method for adding at the end of a singly linked list in a constant time. I don't know how to assign a pointer to the last node in the list in constant time. This method runs in 0(n): </p>
  
  <pre><code>public void insertEnd(Object obj) {
  if (head == null) {
    head = new SListNode(obj);
  } else {
    SListNode node = head;
    while (node.next != null) {
      node = node.next;
    }
    node.next = new SListNode(obj);
  }
  size++;
  }
  </code></pre>
  
  <p>This is a beginning of my new method:</p>
  
  <pre><code>public void addLast(SListNode obj){
    //if the list is empty, the new element is head and tail
    if(tail == null){  
        obj.next = null;
        head = tail = obj;
    }else{   -----&gt; here I'm confused 
  
    }
  }
  </code></pre>
  
  <p>This is my SList class:</p>
  
  <pre><code>public class SList {
     private SListNode head;
     private SListNode tail;
     private int size;
  
     public SList() {
     size = 0;
     head = null;
     tail = null;
  
  }
  </code></pre>