public static void printTree(Node head) {
System.out.println("Binary Tree:");
printInOrder(head, 0, "H", 17);
System.out.println();
}
public static void printInOrder(Node head, int height, String to, int len) {
if (head == null) {
return;
}
printInOrder(head.right, height + 1, "v", len);
String val = to + head.value + to;
int lenM = val.length();
int lenL = (len - lenM) / 2;
int lenR = len - lenM - lenL;
val = getSpace(lenL) + val + getSpace(lenR);
System.out.println(getSpace(height * len) + val);
printInOrder(head.left, height + 1, "^", len);
}
06-09
303
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-20
1245
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-04
522
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-23
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交