This method adds a comparable object to a binary tree. Can anyone tell me what I am doing wrong in this code:
<code>
public void add (Comparable x) throws DuplicateException
{
int diff;
BST node= this;
while (node.root != null)
{
if ((diff = x.compareTo (root)) < 0)
node= node.left;
else if (diff > 0)
node= node.right;
else
throw new DuplicateException ("Duplicate value " + x);
}
node.root= x;
node.left= new BST();
node.right= new BST();
size++;
}
</code>
torch: ~/2110/a3$ java BST ape bat cat
ape
false
while correct output should be:
ape bat cat
false
thanks in advance