title: How to count frequency on an sorted linked list (numbers) Java
body: <p>I have a linked list using nodes, also i have a method in which when you add a number the method sort them. so when i finish adding the numbers the output is a sorted list, the problem is that i have to count how many times a number repeats, so perhaps the node method that i have is this one:</p>
  
  <pre><code> class Node {
  
      int value; 
      int freq;
      Node next;
  } private Node root;
  </code></pre>
  
  <p>now I was trying this code in order to save the frequencies of a number comparing the sorted list values.</p>
  
  <pre><code>public void frequencies(){
      Node neew=root;
      Node current = neew.next;
      int x=0;
      while (neew!=null) {
          if(neew.value==current.value){ 
              neew.freq=x+1;       
          }
          else{
         neew=neew.next;
         current=current.next;
          }
      }
  
  }
  </code></pre>
  
  <p>The code doesn't work (obviously) when i run the program the method loops.</p>
  
  <p>I'm new in this stuff, so i don't know exactly what I'm doing wrong, can you guys help me?</p>