To find height of a binary search tree
/* * To find the Height of a BST tree */
public void findHeight(){
if(this.root == null){
System.out.println("BST Tree is Empty ");
}
else
findHeight(this.root);
}
public int findHeight(Tnode temp){
if(temp == null){
System.out.println("BST Tree is Empty ");
return -1;
}
else{
return 1 + Math.max(findHeight(temp.getLeft())
,findHeight(temp.getRight()) ) ;
}
}
Program is running infinitely.Not able to find the reason , It would be
helpfull ,if some one guides me
Thanks in advance
No comments:
Post a Comment