当前有此二叉树: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);
}
我的疑问是如何得到,如果我删除一个叶子,在消息中显示它是左叶还是右叶为:(左叶为空),但如果两个叶子(左叶和右叶)都为空,则直接不显示任何消息。
暂无答案!
目前还没有任何答案,快来回答吧!