binary tree node spacing algorithm help# Java - 爪哇娇娃
z*n
1 楼
I want to print out a tree and the display output is like
4
2 6
1 3 5 7
.....
There are two steps in my algorithm:
First, Using DFS, compute the necessary space for each node. Do the
depth-first traversal AND keep track of which nodes have children so that you
can then print the lines to the children. It is a recursive function.
Second, to use BFS to print node.
I tried to figure out the space for each node, but failed.
Thnaks a lot for your suggestion!
4
2 6
1 3 5 7
.....
There are two steps in my algorithm:
First, Using DFS, compute the necessary space for each node. Do the
depth-first traversal AND keep track of which nodes have children so that you
can then print the lines to the children. It is a recursive function.
Second, to use BFS to print node.
I tried to figure out the space for each node, but failed.
Thnaks a lot for your suggestion!