Java Eclipse进入方法

Java Eclipse进入方法,java,binary-search-tree,Java,Binary Search Tree,我迷恋文字和思想。我正在使用一个多态二叉搜索树,我需要计算树的高度。NoneEmptyTree实现树接口并具有所有必要的方法。我遇到的问题实际上是调用height方法。我不确定我做错了什么,这可能是因为我接近项目,我似乎找不到明显的问题 还有一个名为EmptyTree的类,它也实现了树接口。以下是所有相关方法 public class PolymorphicBST<K extends Comparable<K>, V> { public int height()

我迷恋文字和思想。我正在使用一个多态二叉搜索树,我需要计算树的高度。NoneEmptyTree实现树接口并具有所有必要的方法。我遇到的问题实际上是调用height方法。我不确定我做错了什么,这可能是因为我接近项目,我似乎找不到明显的问题

还有一个名为EmptyTree的类,它也实现了树接口。以下是所有相关方法

public class PolymorphicBST<K extends Comparable<K>, V>  {
    public int height() {
        return this.height();
}

public int height() {
    int lDepth = left.height();
    int rDepth = right.height();

    if (lDepth == 0 || rDepth == 0) {
        return 0;
    } else if (Math.abs(lDepth - rDepth) > 1) {
        return 0;
    }

    return Math.max(lDepth, rDepth) + 1;
}
公共类多态性CBST{
公共整数高度(){
返回这个.height();
}
公共整数高度(){
int lDepth=left.height();
int rDepth=right.height();
if(lDepth==0 | | rDepth==0){
返回0;
}else if(数学绝对值(lDepth-rDepth)>1){
返回0;
}
返回Math.max(lDepth,rDepth)+1;
}
heightAux方法中的代码用于计算树的实际高度。当我调试程序时,无论我插入多少个断点以及按多少次“单步执行”,它都不会离开JUnit类。当我按下resume project时,我只得到一个StackOverflow错误。这是一个学校项目,因此我不会显示所有与问题相关的代码。如果您有任何帮助,我们将不胜感激

所以,我知道已经放弃了辅助方法,因为我认为没有必要获得高度

  public int height() {
       return this.height();

您的height()方法是这样调用自己的。height()。这将进入无限循环,因为没有退出点。

我刚刚解决了问题。我需要让它说root.height。树的根确定它是空树还是非空树。

没有足够的信息,请发布其余代码,例如,在何处以及如何
heightAux()
已定义?方法
int height()
是通过无限递归实现的…是否应该“返回此.height”根据树是空的还是非空的调用相应的类方法?因此,它将根据每个类的height方法终止?我刚刚解决了这个问题。我需要让它说root.height。树的根确定它是空的树还是非空的树。要调用
height
方法嵌套类之外的d:
NameofParentClass.this.height()