[英]AVL tree Height Method StackOverFlow Erroe
I am trying to implement AVL tree.I'm having stackOverFlow on height method. 我正在尝试实现AVL树。我在高度方法上有stackOverFlow。 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.
调试 - 分配唯一值并在遍历节点时进行打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.