由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 如何实现binary tree的从下到上的分层打印?
相关主题
求救: 打印binary tree问个题:get max value from Queue, with O(1)?
A家来两道电面题面试题
CLRS算法书中BFS的疑问一道很难的面试题
昨天被面试的问题Two programming questions...
请教一个系统设计问题 (转载)A家电面
share 面试题thread-safe blockingqueue
这个用stack实现queuethread safe blocking queue问题
如何用JAVA中的circular array of queue 解决Josephus problem? (转载)Java Blocking Queue问题
相关话题的讨论汇总
话题: queue话题: node话题: curr话题: 打印话题: currlevel
进入JobHunting版参与讨论
1 (共1页)
r****o
发帖数: 1950
1
一种方法是用queue和stack,还有别的方法吗?
s******t
发帖数: 2374
2
你是说倒着的BFS?
r****o
发帖数: 1950
3
是啊,怎么打印比较好?

【在 s******t 的大作中提到】
: 你是说倒着的BFS?
s******t
发帖数: 2374
4
正常bfs打印到一个临时的buffer中,然后从buf打出倒序?
p
s********a
发帖数: 1447
5
用queue
要visit的从dequeue
fringe node enqueue
直到所有的都遍历完

【在 r****o 的大作中提到】
: 是啊,怎么打印比较好?
r****o
发帖数: 1950
6
要visit的从dequeue是什么意思

【在 s********a 的大作中提到】
: 用queue
: 要visit的从dequeue
: fringe node enqueue
: 直到所有的都遍历完

l*******g
发帖数: 8
7
一个queue应该就可以了,我把code贴出来了。如果有错误的话,请指正。
printByLevel(Node *root)
{
Queue queue;
int currLevel = 1; /* total number of nodes on the current level */
int currPos = 0; /* current position on the current level */
int nextLevel = 0; /* total number of nodes on the next level */
queue.enqueue(root);
while(currLevel>0)
{
Node *curr = queue.dequeue();
printNode(curr);
if(curr->left){
queue.enqueue(curr->left);
nextL
s******t
发帖数: 2374
8
他的意思是要反向打印
比如:
a
b c
d e f g
打印成
d e f g
b c
a

*/
*/

【在 l*******g 的大作中提到】
: 一个queue应该就可以了,我把code贴出来了。如果有错误的话,请指正。
: printByLevel(Node *root)
: {
: Queue queue;
: int currLevel = 1; /* total number of nodes on the current level */
: int currPos = 0; /* current position on the current level */
: int nextLevel = 0; /* total number of nodes on the next level */
: queue.enqueue(root);
: while(currLevel>0)
: {

c******f
发帖数: 2144
9
是不是用1个queue一个deque?
r****o
发帖数: 1950
10
自己顶一下。

【在 r****o 的大作中提到】
: 一种方法是用queue和stack,还有别的方法吗?
r****o
发帖数: 1950
11
请各位大牛出招啊。

【在 r****o 的大作中提到】
: 一种方法是用queue和stack,还有别的方法吗?
s******t
发帖数: 2374
12
queue或者stack不是挺好的么?为啥一定要其他的?转化成递归?我不sure是不是能做
。。。没仔细想过。
BTW:我不是大牛。。。。我是打酱油的。

【在 r****o 的大作中提到】
: 请各位大牛出招啊。
r****o
发帖数: 1950
13
以前看到过版上的牛人讨论过一个很好的方法,找不到链接了。

【在 s******t 的大作中提到】
: queue或者stack不是挺好的么?为啥一定要其他的?转化成递归?我不sure是不是能做
: 。。。没仔细想过。
: BTW:我不是大牛。。。。我是打酱油的。

1 (共1页)
进入JobHunting版参与讨论
相关主题
Java Blocking Queue问题请教一个系统设计问题 (转载)
这个Java blocking queue实现是不是有问题?share 面试题
再问一个blockingqueue的问题这个用stack实现queue
用queue 做树的广度优先遍历,空间复杂度是多少?如何用JAVA中的circular array of queue 解决Josephus problem? (转载)
求救: 打印binary tree问个题:get max value from Queue, with O(1)?
A家来两道电面题面试题
CLRS算法书中BFS的疑问一道很难的面试题
昨天被面试的问题Two programming questions...
相关话题的讨论汇总
话题: queue话题: node话题: curr话题: 打印话题: currlevel