由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - print a BST level by level, last row first
相关主题
Level order traversal只让用一个Queue怎么做?Google点面
Bloomberg on-campus interview (failed) 求教面经分享
[面试题] 如何打印一个二叉树level by level?求救: 打印binary tree
这个题目有什么trick大牛公司的实际工作中也要处理类似面试题一样的难题吗
A电面一题 基本已挂Amazon面经
Amazon的序列化二叉树电面题BFS traverse O(1) space?
我恨iPhone@Facebook电面FB两次电面
如何实现binary tree的从下到上的分层打印?Finding deepest node of BST ?
相关话题的讨论汇总
话题: level话题: queue话题: bst话题: print话题: stack
进入JobHunting版参与讨论
1 (共1页)
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实现

1 (共1页)
进入JobHunting版参与讨论
相关主题
Finding deepest node of BST ?A电面一题 基本已挂
问个老题Amazon的序列化二叉树电面题
为什么我做了快1000道题了,还是不行呢?!我恨iPhone@Facebook电面
A家一道onsite题如何实现binary tree的从下到上的分层打印?
Level order traversal只让用一个Queue怎么做?Google点面
Bloomberg on-campus interview (failed) 求教面经分享
[面试题] 如何打印一个二叉树level by level?求救: 打印binary tree
这个题目有什么trick大牛公司的实际工作中也要处理类似面试题一样的难题吗
相关话题的讨论汇总
话题: level话题: queue话题: bst话题: print话题: stack