title: How to add a node at specified index in LinkedList implementation
body: <p>So I am implementing a LinkedList from scratch and one method, insertAt(int index, T elem), is really giving me a headache. The method is supposed to insert a node at the specified index and move the rest of the list accordingly. My implementation seems to just copy and paste existing nodes. Any help on what I am doing wrong? (use cases below)</p>
  
  <p>Let me know if it would help to include the interface notes or the full class:</p>
  
  <pre><code>public class LinkedList&lt;T&gt; implements ListInterface&lt;T&gt; {
  
  private Node&lt;T&gt; first;
  private Node&lt;T&gt; last;
  private int counter;
  
  public LinkedList() {
  }
  
  @Override
  public ListInterface&lt;T&gt; insertAt(int index, T elem) {
      if(index &gt; counter) {
          throw new IndexOutOfBoundsException();
      }
      Node&lt;T&gt; node = new Node&lt;T&gt;(null, elem, null);
      if(counter == 0) {
          first = last = node;
      }
      else {
          if(index == 0) {
              node.next = first;
              first.prev = node;
              first = node;
          }
          else if(index  == counter) {
              node.prev = last;
              last.next = node;
              last = node;
          }
          else {
              Node&lt;T&gt; current = this.first;
  
              for(int i = 0; i &lt; index; i++) {
                  current = current.next;
              }
              node.next = current;
              node.prev = current.prev;
              current.prev.next = node;
          }
      }
      counter++;
      return this;
  }
  </code></pre>
  
  <p><strong>Node Class:</strong></p>
  
  <pre><code>public class Node&lt;T&gt; {
  
  public T data;
  public Node&lt;T&gt; next;
  public Node&lt;T&gt; prev;
  
  public Node(Node&lt;T&gt; prev, T data, Node&lt;T&gt; next){
      this.data = data;
      this.next = next;
      this.prev = prev;
  }
  
  public Node() {
  
  }
  </code></pre>
  
  <p><strong>Usage Example #1 (Wrong Answers):</strong></p>
  
  <pre><code>      LinkedList&lt;String&gt; list = new LinkedList &lt;String&gt;();
        list.insertFirst("p");
        list.insertFirst("a");
        list.insertFirst("e");
        list.insertFirst("h");
  
        list.insertAt(2, "A");
  </code></pre>
  
  <p><strong>Console:</strong></p>
  
  <p>Before: {h, e, a, p} </p>
  
  <p>After: {h, e, e, a, p}</p>
  
  <p><strong>What Console SHOULD BE:</strong></p>
  
  <p>Before: {h, e, a, p} </p>
  
  <p>After: {h, e, A, a, p}</p>