0
点赞
收藏
分享

微信扫一扫

二叉树_查找值为x的结点

紫荆峰 2022-04-14 阅读 47
java

在这里插入图片描述
构造的二叉树同上:https://blog.csdn.net/weixin_51995229/article/details/124173365?spm=1001.2014.3001.5501

public BTNode find(char x) {
        return find(root, x);
    }

    private BTNode find(BTNode t, char x) {
        BTNode p;
        if (t == null)//递归出口
            return null;
        if ((char) t.data == x)//找到了
            return t;
        else {
        	//找该结点左子树
            p = find(t.lchild, x);
            if (p != null)
                return p;
            //左子树没找到的话,找右子树
            p = find(t.rchild, x);
            if (p != null)
                return p;
            else
                return null;
        }
    }
举报

相关推荐

0 条评论