Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AVL树-必需:字符串,找到:AVL_Java_Algorithm_Tree - Fatal编程技术网

Java AVL树-必需:字符串,找到:AVL

Java AVL树-必需:字符串,找到:AVL,java,algorithm,tree,Java,Algorithm,Tree,AVLStringTreeNode的构造函数: static String min ( AVLStringTreeNode t ) { if( t == null ) return t; while( t.left != null ) // location of error t = t.left; return t.val; } 错误: public class AVLStringTreeNode { public String

AVLStringTreeNode的构造函数:

static String min ( AVLStringTreeNode t ) {
    if( t == null )
        return t;
    while( t.left != null ) // location of error
        t = t.left;
    return t.val;
}
错误:

public class AVLStringTreeNode
{
    public String val;
    public int height;
    public AVLStringTreeNode left, right;
}

我看不出密码有什么问题。我做错了什么?

返回类型是String,但当t为null时,返回t,即AVLStringTreeNode

试试这个:

incompatible types required: java.lang.String found: AVLStringTreeNode

我认为你必须像这样重新编写你的while代码-

static String min ( AVLStringTreeNode t ) {
    if( t == null )
        return null;
    while( t.left != null ) // location of error
        t = t.left;
    return t.val;
}
发生此错误的原因可能是一旦
t.left
变为空。所以它检查null

希望能有所帮助。

非常感谢

是运行时错误吗?是编译错误
while( t.left != null ){
   if(t.left!=null){     
      t = t.left; 
  }
}