title: Help making a singly linked list in Java
body: <p>This is for homework but please know that I have looked online for help (such as <a href="http://www.sethi.org/classes/class_stuff/cis435/others/notes-java/data/collections/lists/simple-linked-list.html" rel="nofollow noreferrer">http://www.sethi.org/classes/class_stuff/cis435/others/notes-java/data/collections/lists/simple-linked-list.html</a>) and my textbook but I am still having some issues.</p>
  
  <p>Any help would be appreciated...</p>
  
  <p>Right now I'm trying to just insert values in but nothing is working. Whether it's the first item, whether it's being added as the last one, or somewhere in between.</p>
  
  <pre><code>Node header = null;    // First element of list.
  Node back  = null;    // Last element of list.
  
  public void insert(int i, double value){ //insert value before i-th element
    Node e = new Node();
    e.num = value;
    Node curr = header;
    for(int x=0;x&lt;i;x++) {
     if (i == 1) { //we want to insert as first thing
      if (size == 0) { //its the FIRST time we add something
       header.next = e;
       e.next = back;
       break;
      } else if (size == 1){
       e.next = header.next; //i.e. the second thing in the list
       header.next = e;
       break;
      } else {
       e.next = header.next.next; //i.e. the second thing in the list
       header.next = e;
       break;
      }
     }
     else if (x == (i-1)) {
      e.next = curr.next;
      curr.next = e;
      break;
     }
     curr = curr.next;
    }
    size = size+1;
   }
  </code></pre>
  
  <p>Not really sure why it isn't working.</p>
  
  <p>Thanks!</p>