title: Custom LinkedList: remove method does not work as expected
body: <p>I'm implementing the <code>remove()</code> method of a custom <code>LinkedList</code> class, but it does not remove any items from the list, and I can't figure out why.</p>
  
  <p>Here's how I do it:</p>
  
  <pre><code>public void remove(int position) {
          if (position &lt; 0 || position &gt;= size) {
              throw new IndexOutOfBoundsException(
                      "position should be beween 0 and size - 1");
          }
  
          Cell current = top;
          for (int i = 0; i &lt; position; i++) {
              current = current.next;
          }
          current = current.next.next;
          size--;
  }
  </code></pre>
  
  <p>This method tries to remove an item between 2 nodes (removing first node and last node cases are ignored).</p>
  
  <p>This is the test case I am executing, and after trying to remove the element with index 2, it still prints the hole list:</p>
  
  <pre><code>CustomList&lt;String&gt; list = new CustomList&lt;String&gt;();
  list.add("Hello");
  list.add("morena");
  list.add("What");
  list.add("Miranda");
  list.add("Aston");      
  
  list.remove(2);
  
  list.printAll();
  </code></pre>
  
  <p>For completion, here's the full implementation of the list:</p>
  
  <pre><code>public class CustomList&lt;T&gt; {
  
      private class Cell {
          T data;
          Cell next;
  
          public Cell(T data) {
              this.data = data;
          }
      }
  
      private Cell top;
      private int size;
  
      public void add(T data) {
          addAtEndInOn(data);
          size++; 
      }
  
      /**
       * adds an item at the end of the list in O(n) by iterating the whole list
       * before adding the node
       */
      private void addAtEndInOn(T data) {
          if (top == null) {
              top = new Cell(data);
          } else {
              Cell current = top;
              while (current.next != null) {
                  current = current.next;
              }
              current.next = new Cell(data);
          }
      }
  
      public void remove(int position) {
          if (position &lt; 0 || position &gt;= size) {
              throw new IllegalArgumentException(
                      "position should be a positive number");
          }
  
          Cell current = top;
          for (int i = 0; i &lt; position; i++) {
              current = current.next;
          }
          current = current.next.next;
          size--;
      }
  
      public void printAll() {
          Cell current = top;
          while (current != null) {
              System.out.println(current.data);
              current = current.next;
          }
      }
  }
  </code></pre>