title: How to properly remove one node from a generic linked list?
body: <p>I am trying to remove one node from the generic linked list instead of removing the whole list. I want it to remove one item of comparable type. I am trying to find the proper way of doing this. I also need it to go to the last node to be ready to add a node after removing a node.</p>
  
  <pre><code>
  
  
  
  
  
  import java.util.Scanner;
  
  
  import java.io.*;
  
  
  class MyGenericList &lt;T extends Comparable&lt;T&gt; &gt;
  {
      private  class Node&lt;B&gt;
       {
          T value;
          Node&lt;T&gt;  next;
       }   
  
       private Node&lt;T&gt; first = null;
       int count = 0;
  
      public void  add(T element)
       {
           Node&lt;T&gt; newnode = new Node&lt;T&gt;();
           newnode.value = element;
           newnode.next = null;
  
          if (first == null)
          {
              first = newnode;
          }
          else
          {
              Node&lt;T&gt; lastnode = gotolastnode(first);
              lastnode.next = newnode;
          }
           count++;
       }
  
      public void remove(T element)
      {
          Node&lt;T&gt; newnode = new Node&lt;T&gt;();
          Node&lt;T&gt; prevnode = new Node&lt;T&gt;();
          Node&lt;T&gt; curnode = new Node&lt;T&gt;();
  
          prevnode.value = element;
          curnode.next = null;
          int hopcount=0;
  
          while(hopcount &lt; count)
          {
              if(prevnode == element)
              {
                  prevnode.next = first;
                  Node&lt;T&gt; lastnode = gotolastnode(first);
                  lastnode.next = newnode;
              }
  
              hopcount++;
          }
          count--;
         }
  
      public T get(int pos)
      {
           Node&lt;T&gt; Nodeptr = first;
           int hopcount=0;
           while (hopcount &lt; count &amp;&amp; hopcount&lt;pos)
           {   if(Nodeptr != null)
               {
                  Nodeptr = Nodeptr.next;
               }
               hopcount++;
           }
          return  Nodeptr.value;
      }
  
      private Node&lt;T&gt; gotolastnode(Node&lt;T&gt; nodepointer) 
      {
         if (nodepointer== null )
          {
            return nodepointer;
          } 
          else
          {
              if (nodepointer.next == null)
                 return nodepointer;
              else
                   return gotolastnode( nodepointer.next);
  
          }
  
      }
  }
  
  class Employee implements Comparable&lt;Employee&gt;
  {
      String name;
      int age;
      @Override
      public int compareTo(Employee arg0) 
      {
          // TODO Auto-generated method stub
          return 0;
          // implement compareto method here. 
      }
      Employee( String nm, int a)
      {
          name =nm;
          age = a;
      }
  }
  
  class City implements Comparable&lt;City&gt;
  {
  
      String name;
      int population;
      City( String nm, int p)
      {
          name =nm;
          population = p;
      }
      @Override
      public int compareTo(City arg0) {
          // TODO Auto-generated method stub
          return 0;
          // implement compareto method here. 
      }
  
  }
  public class GenericLinkedList
  {
  
      public static void main(String[] args) throws IOException
      {
          MyGenericList&lt;Employee&gt; ml = new MyGenericList&lt;&gt;();
  
          ml.add(new Employee("john", 32));
          ml.add(new Employee("susan", 23));
          ml.add(new Employee("dale", 45));
          ml.add(new Employee("eric", 23));
  
          Employee e1 = ml.get(0);
         System.out.println(  "Name " + e1.name + " Age "+ e1.age );
  
         ml.remove(new Employee("john", 32));
         System.out.println(  "Name " + e1.name + " Age "+ e1.age );
  
         ml.add(new Employee("john", 32));
         System.out.println(  "Name " + e1.name + " Age "+ e1.age );
  
  
         MyGenericList&lt;City&gt; citylist = new MyGenericList&lt;&gt;();
  
          citylist.add(new City("Los Angeles", 320000));
          citylist.add(new City("Santa monica", 230000));
          citylist.add(new City("San Francisco", 450000));
          citylist.add(new City("San Diego", 23000));
          City c= citylist.get(2);
          System.out.println(  "City " + c.name + " Population "+ c.population );
      }
  }
  
  
  
  
  
  
  
  </code></pre>
  
  <p>Instead of removing the whole list I would like to remove one.</p>