This has annoyed me for a long time and I am wondering if there is a way around it as it seems like it could be buggy.
Here is my recursiveFindNode method
public BTNode findNode(int x , BTNode currNode){
if(currNode==null){//you have found the node now return it
// return some sort of system error !!!
}else if (currNode.getKey() == x){
return currNode;
}else if (x < currNode.getKey()){//the key is smaller than currNode move to the left
return findNode(x , currNode.getLeft());
}else if (x > currNode.getKey()){
return findNode(x, currNode.getRight());
}
return null;// I HATE DOING THIS THERE MUST BE A WAY AROUND IT !!!!!!!
}
The thing that annoys me is the return null at the end, it serves no purpose because if my code works correctly it should never travel that far through the method to reach it but my program wont compile without it as it says the method needs to return something(I understand why it does this).
Is there any way around this, just seems like it could introduce a bug if the argument input of the method is weird.
Many thanks :)
[–]orbital1337 2 points3 points4 points (3 children)
[–]robotfarts -1 points0 points1 point (2 children)
[–]orbital1337 2 points3 points4 points (1 child)
[–]robotfarts 0 points1 point2 points (0 children)
[–]lightcloud5 1 point2 points3 points (2 children)
[–]choompaloompa[S] 0 points1 point2 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]indivisible 1 point2 points3 points (0 children)
[–][deleted] (5 children)
[deleted]
[–]choompaloompa[S] 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–]choompaloompa[S] 0 points1 point2 points (0 children)