title: Counting frequency of generic object in a binary tree
body: <p>Im creating a method to count the frequency of a value that is the methods parameter. I have created a binary tree and put values into it, im now trying to count all the values that equals the parameter.
  The problem is im getting a infinite loop, can anybody see why:</p>
  
  <pre><code>public int counter(T value)
    {
       if (value == null) return 0;
        Node&lt;T&gt; p = root, q = null; // q is the parent of p
        int values = 0;
  
  
      while (p != null)                           // checks p
      {
        int cmp = comp.compare(p.value,value);// compares
  
        if(p.value.equals(value))
        {
            values++;
        }
  
        if (cmp &lt; 0) { q = p; p = p.left; }      // goes left in the tree
        else if (cmp &gt; 0) { q = p; p = p.rigth; }  goes right in the tree
  
  
       if ( p == null) return values;
          }
  
  
        return 0; // if no values found in the tree 
    }
  </code></pre>
  
  <p>Constructor:</p>
  
  <pre><code>   private Node(T value, Node&lt;T&gt; l, Node&lt;T&gt; r) 
      {
        this.value = value;
        left = l; right = r;
      }
  </code></pre>