Redian新闻
>
binary tree node spacing algorithm help
avatar
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!
avatar
g*g
2
I don't see why you need DFS first,
use a Q, BFS is straight. Use a function to format
your number to fix length before prin out.

【在 z****n 的大作中提到】
: 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.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。