0

Hi, I am trying to code a program which will allow a user to search through a .db file for a word which is specified through an argument. The main class is in a different file. I am having a hard time putting the contents from the DB file into a binary search tree. "tree.put" is called from the main file. Can someone please tell me why this code isnt working?

// Development version of treemap.
// To be deleted and replaced by an actual implementation that
// does *NOT* use java.util.TreeMap.

import static java.lang.System.*;

class treemap {

  public class tree {
     public String key;
     public String value;
     public  tree left;
    public  tree right;

        public tree(String s){
                 key= s;
                left=null;
                right=null;
        }

   }

   tree root = null;

   java.util.TreeMap <String, String> tree
         = new java.util.TreeMap <String, String> ();


public String get (String key) {
        tree newNode = new tree(key);
        if(key.compareTo(newNode.key)>0){
                System.out.println(">0");
        }
        if(key.compareTo(newNode.key)<0){
                System.out.println("<0");
        }
        else System.out.println("Found");

}
 public String put (String key) {
        tree newNode = new tree(key);
        if(root == null) root = newNode;
        if(root!=null){
                if(key.compareTo(newNode.key)>0){
                        if(newNode.left==null) newNode.left= newNode;
                else left.put(newNode);
                }
                else if(key.compareTo(newNode.key)<0){
                        if(newNode.right == null) newNode.right = newNode;
                        else newNode.right.put(newNode);
                }
   }
}
private void debug_tree_recur (tree node, int depth) {
   }

   public void debug_tree () {
      debug_tree_recur (root, 0);
   }


}

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by BestJewSinceJC
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.