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){

            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){

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



public boolean searchTree(TreeNode root, String item){
           if(root == null){
               return false;

               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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.