I have a OBTComparable and am testing it to find strings, it doesn't work however! Can anyone see where I've gone wrong? Any help would be appreciated, the code is as below.
OBTComparable.java
public class OBTComparable { private boolean empty; private Comparable value; private OBTComparable left; private OBTComparable right;
public OBTComparable() { setEmpty(); } // constructor
private void setEmpty() { empty = true; value = null; left = null; right = null; } // setEmpty
public boolean isEmpty() { return empty; }
public Comparable getValue() { return value; }
public OBTComparable getLeft() { return left; }
public OBTComparable getRight() { return right; }
private void setValue(Comparable requiredValue) { if (empty) { empty = false; left = new OBTComparable(); right = new OBTComparable(); } value = requiredValue; } //setValue
public void insert(Comparable insertValue) { if (empty) setValue(insertValue); else if (insertValue == value) left.insert(insertValue); else right.insert(insertValue); } // insert
public boolean find(Comparable findValue) { if (empty) return false; else if (findValue == value) return left.find(findValue); else return right.find(findValue); } // find } // class OBTComparable
FindTest.java
import java.util.*;
class FindTest { public static void main(String args[]) { String [] insertStrings = new String [] {"My", "name", "is", "John", "Latham", "and", "my", "hobbies", "include", "films", "music", "electronics", "and", "computing"};
for (int i = 0; i <= 13; i++) { compareMe.insert(insertStrings); System.out.println("Inserting" + " " + insertStrings); } for (int i = 0; i <= 7; i++) { boolean result = compareMe.find(searchStrings);