tricket_7 -3 Newbie Poster

How do I implement a frequency counter in a treenode that increases when the user enters an existing word?

I have a program where the user is asked to choose: enter string, search for string

My frequency counter is not working properly. How do I keep track of the frequencies for the left and right nodes? My frequency counter only gives for root:

public void insert(String item){

        if(isEmpty()){      
            root = new TreeNode(item); 
                        System.out.println("inserted " + "'" + item + "'" + " into tree. Frequency: " + root.getFreq());
                }
               // If string item already exists, do not insert another node, increase the frequency of the node containing the string
                        else if(searchTree(root,item) == true){
                            root.upFreq();

                            System.out.println( "'" + item + "'" + " already exists! Frequency: " + root.getFreq());
                 //if the string does not already exists, enters string item into new node       
                        } else{                           
                    root.add(item); 
                    System.out.println("inserted " + "'" + item + "'" + " into tree! Frequency: " + root.getFreq());

        }  

        }





public boolean searchTree(TreeNode root, String item){
           if(root == null){
               return false;
           }
           if(root.item.equals(item)){ 
              //root.upFreq();

               return true;            
           }
           return searchTree(root.left, item) || searchTree(root.right, item);
           }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.