毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

怎么用java先序创建二叉树源代码 第3页

更新时间:2012-12-7:  来源:毕业论文
;                   
if(p != null){

    int ld = height(p.left);//返回左子树的高度
    int rd = height(p.right);//返回右子树的高度
    return (ld >= rd) ? ld+1 : rd+1;//当前子树的高度为较高子树的高度加1
}else
    return 0;
   
    }

    //获得父母结点
    public BinaryNode<E> getParent(BinaryNode<E> node){//返回node的父母结点,若为空树、未找到或node为根,返回null

if((root == null) || (node == null) || (node == root))
    return null;
    else
    return getParent(root,node);
    }

    private BinaryNode<E> getParent(BinaryNode<E> p,BinaryNode<E> node){//在以p为根结点的子树中查找并返回node结点的父母结点

BinaryNode<E> find = null;
if(p != null){

    if(p.left == node || p.right == null)
find = p;//查找成功

    else{

find = getParent(p.left,node);//在左子树中查找
if(find == null)
    find = getParent(p.right,node);//若左子树中未找到,则继续在右子树中查找
    }
}
return find;//返回找到的父母结点
    }

    //获得左、右孩子
    public BinaryNode<E> getLChild(BinaryNode<E> node){//返回node的左孩子,若为空树、未找到或node为叶子,返回null

  if((root == null) || (node == null) || (node.left == null) || (node.right == null))
    return null;
else
    return node.left;
    }

    public BinaryNode<E> getRChild(BinaryNode<E> node){//返回node的右孩子,若为空树、未找到或node为叶子,返回null

  if((root == null) || (node == null) || (node.left == null) || (node.right == null))
    return null;
else
    return node.right;
&n

上一页  [1] [2] [3] [4] 下一页

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©chuibin.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。