I have a class that uses an internal binary tree as a data structure. I have a weird problem. I'm recursively looking for a specific node. If the node is found I want the code to return the reference to it. The problem: After return it's always null! But why?
private HeapNode getHeapNode(double key) {
//ELEMENT IS NOT AVAILABLE HERE, NULL-Pointer, ALWAYS
return getHeapNodeRec(key, rootHeapNode);
}
private HeapNode getHeapNodeRec(double key, HeapNode curr) {
if (curr == null) {
return null;
}
if (curr.getKey() == key) {
//ELEMENT IS AVAILABLE HERE, I can access its data!
return curr;
}
else {
getHeapNodeRec(key, curr.getLeft());
getHeapNodeRec(key, curr.getRight());
}
return null;
}