H*M 发帖数: 1268 | 1 Write the code to print a Binary tree level by level STARTING FROM THE
LEAF LEVEL and then give exhaustive test cases.
eg: 1
2 3
4 5 6 7
Output: 4567
23
1
I am thinking of using BFS. use a queue. push right child first then left
child.
also push everything popped from queue to a stack. finally pop from the
stack.
use "null" to delimit the new line.
I feel it is not good. any better ideas? | g*******y 发帖数: 1930 | 2 我之前的帖子里面问到过这个的
这个题里面stack+queue合起来的效果,可以用一个array实现 | H*M 发帖数: 1268 | 3 Miao!!
u mean by using array, we dont really need to pop, we just keep an index, wh
ich otherwise should be"popped"..append all the childen at the end of the ar
ray. finally read the array in reverse order.....
so the space of the queue is saved.
【在 g*******y 的大作中提到】 : 我之前的帖子里面问到过这个的 : 这个题里面stack+queue合起来的效果,可以用一个array实现
|
|