How can I do the test without error?
Because of that object can not be used in this operator?
i have error(in insert function) why?
The error:
The operator < is undefined for the argument type(s) java.lang.Object, java.lang.Object
public class BinarySearchNode {
protected Object data;
protected BinarySearchNode left;
protected BinarySearchNode right;
public BinarySearchNode(Object data) {
if (data == null)
throw new RuntimeException("we are too lazy to deal with null data");
this.data = data;
this.left = null;
this.right = null;
}
public void insert(Object toAdd) {
if **(toAdd < data)** { <<<<<<<<<<<<<<<<<<< here
if (left == null)
left = new BinarySearchNode(toAdd);
else
left.insert(toAdd);
} else {
if (right == null)
right = new BinarySearchNode(toAdd);
else
right.insert(toAdd);
}
}
public void InOrderPrint() {
if (left != null)
left.InOrderPrint();
System.out.println(this.data);
if (right != null)
right.InOrderPrint();
}
}