I searched the tree to find the passed value. Unfortunately this will not work. I started debugging it with fingerprints, and strangely enough, it does find the value, but skips the return statement.
private TreeNode searchNodeBeingDeleted(Comparable c, TreeNode node)
{
if(node == null)
{
return null;
}
if(c.equals((Comparable)node.getValue()))
{
System.out.println("Here");
return node;
}
else
{
if(node.getLeft() != null)
{
System.out.println("left");
searchNodeBeingDeleted(c, node.getLeft());
}
if(node.getRight() != null)
{
System.out.println("right");
searchNodeBeingDeleted(c, node.getRight());
}
}
return null;
}
It displays the results as follows:
left
left
right
right
Here
right
left
right
left
right
Exception in thread "main" java.lang.NullPointerException
at Program_14.Driver.main(Driver.java:29)
I don't know if this will help, but here is my tree:
L
/ \
D R
/ \ / \
A F M U
\ / \
B T V
Thank you for your time.
source
share