如果一个二叉树的叶子是空的,说明哪个叶子是空的

g2ieeal7  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(234)

当前有此二叉树:https://i.stack.imgur.com/zqcjh.png
我的代码是这样的:

private void print2DUtil(NodeA root, int space)
{
    // Base case
    if (root == null)
        return;
    // Increase distance between levels
    space += COUNT;
 // Print current node after space
    // count
    for (int i = COUNT; i < space; i++)
        System.out.print(" ");
    Carta aux=root.inf;
    aux.Visualizar();
    System.out.print( "\n"); 
    // Process left child first
    print2DUtil(root.left, space);
    // Process right child
    print2DUtil(root.right, space);
}

// Wrapper over print2DUtil()
public void print2D()
{
    // Pass initial space count as 0
    print2DUtil(this.arrel, 0);
}

我的疑问是如何得到,如果我删除一个叶子,在消息中显示它是左叶还是右叶为:(左叶为空),但如果两个叶子(左叶和右叶)都为空,则直接不显示任何消息。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题