Java 如果二叉树的叶子是空的,说出哪个叶子是空的

Java 如果二叉树的叶子是空的,说出哪个叶子是空的,java,tree,binary-tree,tostring,Java,Tree,Binary Tree,Tostring,当前有此二叉树: 我的代码是这样的: 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 =

当前有此二叉树:

我的代码是这样的:

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);
}
private void print2DUtil(NodeA root,int space)
{
//基本情况
if(root==null)
返回;
//增加级别之间的距离
空格+=计数;
//在空格后打印当前节点
//计数
for(int i=COUNT;i
我的疑问是,如果我删除一个叶子,在消息中显示它是左叶还是右叶:(左叶为空),但如果两个叶子(左叶和右叶)都为空,则直接不显示任何消息