For some reason the add(value) function doesn't want to work. I should be able to use Node and TreeNode to create a child. This isn't a balanced tree. I tried both Node and NodeTree and to make a variable with the node and adding it in with no success
public abstract class TreeNode implements Comparable<TreeNode>{
protected int value;
protected TreeNode left;
protected TreeNode right;
public abstract int getValue();
public abstract int getSize();
public abstract TreeNode getLeft();
public abstract TreeNode getRight();
public void add(int value){
if (value >= this.value){
if (this.right == null){
this.right = new Node(value); //trying to put a node in the "right"
}else{
right.add(value);
}
}else if(value < this.value){
if (this.left == null){
this.left = new Node(value); //trying to do the same thing here
}else{
left.add(value);
}
}
}
public String toString() {
return (left.toString() + ", " +Integer.toString(this.value) + ", " + right.toString());
}
public int CompareTo(TreeNode obj){
if(this.value > obj.value){
return 1;
}else if(this.value < value){
return -1;
}else{
return 0;
}
}
//public void remove(int value) throws NotFoundException{
//}
}