Why is false being returned in this function
Posted
by Kay
on Stack Overflow
See other posts from Stack Overflow
or by Kay
Published on 2010-04-25T20:29:55Z
Indexed on
2010/04/25
20:33 UTC
Read the original article
Hit count: 165
java
Hello all,
I have this function below which makes it to the second IF function which sets the variable th
as true but what is returned is false? Why?!
public boolean nodeExist(TreeNode Tree, T value){
boolean th = false;
if(Tree.getValue()!= null){
if(value == Tree.getValue()){
th = true;
}else{
if(value.compareTo((T) Tree.getValue()) < 0){
nodeExist(Tree.getLeft(), value);
}else{
nodeExist(Tree.getRight(), value);
}
}
}else{
th = false;
}
return th;
}
© Stack Overflow or respective owner