Java AVL树-必需:字符串,找到:AVL
AVLStringTreeNode的构造函数: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
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;
}
}