title: Removing a specific item from LinkedList in java without using any API
body: <p>I am trying to remove an item from the LinkedList in java. This List is implemented by me and I am not using any java API. The major trouble I am facing is with RECURSION as I am always lost in recursion coding.</p>
  
  <pre><code>class List{
  
      int N;
      List next;
      List current;
      List(int N){
          this.N =N;
          this.next = null;
      }
  
      @Override
      public String toString() {
          String o = "";
          List curr = this;
          while(curr != null){
              o += curr.N+"--&gt;";
              curr = curr.next;
          }
  
          return o+"TAIL";
      }
  }
  </code></pre>
  
  <p>Method implemented:</p>
  
  <pre><code>private static List Remove(List L,int N){
      if(L == null || L.next == null)
          return L;
  
      List current = L;
      List previous = null;
  
      while(current != null){
          if(current.N == N){
              current = current.next;
              if(previous == null)previous = current;
              else{
                  previous.next = current;
              }
              break;
          }else{
              previous = current;
              current = current.next;             
          }   
      }
      return previous;
  }
  </code></pre>
  
  <p>Input -</p>
  
  <pre><code>List list1 = new List(1);
          list1.next = new List(2);
          list1.next.next = new List(3);
          list1.next.next.next  = new List(4);
          list1.next.next.next.next  = new List(5);
          list1.next.next.next.next.next  = new List(6);
          list1.next.next.next.next.next.next  = new List(7);
  System.out.println("Before Removal "+list1.toString());
          System.out.println("After Removal "+Remove(list1,3));
  </code></pre>
  
  <p>Output I am getting is -</p>
  
  <ul>
  <li>Before Removal 1-->2-->3-->4-->5-->6-->7-->TAIL </li>
  <li>After Removal 2-->4-->5-->6-->7-->TAIL</li>
  </ul>
  
  <p>Here I am losing the value 1 as I am setting the <code>current = current.next</code> or reference is being set to next value. So definitely I am having some problem with the presentation of data stored in different references.</p>