gpt4 book ai didi

java - AVL 树 - 找到所需的 : String,:AVL

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:44:32 26 4
gpt4 key购买 nike

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

AVLStringTreeNode 的构造函数:

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

错误:

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

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

最佳答案

你的返回类型是String,当t为null时,你返回t,即AVLStringTreeNode。

试试这个:

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

关于java - AVL 树 - 找到所需的 : String,:AVL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28987272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com