I am trying to implement AVL tree.I'm having stackOverFlow on height method. I tried with small number of inputs it works. However, When i tried with large scale of input, it crush. Here is my code.
private int height(Node<T> node){
if(!isEmpty() && node != null){
if(isleaf(node))
return 1;
else{
int p = height(node.left);
int q = height(node.right);
if(p > q)
return p + 1;
else
return q + 1;
}
}
return 0;
}
This can happen if your tree has cyclic references. Check tree construction. To debug - assign unique values and print while traversing the nodes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.