在二叉树中搜索特定单词

Searching a binary tree for a specific word

我需要在二叉树中找到给定的单词。我有这个代码

if (n !=null)
{
    if((name.compareTo(n.getVehicleName()) < 0) && n.left())
    {
        return find(name.hasLeft, n);
    }
    if((name.compareTo(n.getVehicleName()) > 0) && n.hasRight())
    {
        return find(name.right, n);
    }
    if(name.compareTo(n.getVehicleName()) == 0)
    {
        return Vehicle;
    }
}

我没有工作,我不知道如何解决。

我得到的唯一帮助是:

* @param name  The name of the vehicle to search for
* @param n     The current node in the tree to search from
* @return      A reference to the node that was found or null if not found 

int order = name.compareTo(n.getVehicleName());

if(n==null) return null

return null;

我将首先解决一些主要问题并添加一个案例,如果你在一片叶子上但仍然没有找到这个词,它 returns null。

if (n != null)
{
    if(name.compareTo(n.getVehicleName()) < 0))
    {
        if(name.hasLeft()){
            return find(name.left, n);
        }else{
            return null
        }
    }
    else if((name.compareTo(n.getVehicleName()) > 0))
    {
        if(name.hasRight()){
            return find(name.right, n);
        }else{
            return null
        }
    }
    else if(name.compareTo(n.getVehicleName()) == 0)
    {
        return Vehicle;
    }
}