主题:[讨论]二叉树宽度算法
			 honesy
				 [专家分:90]  发布于 2008-01-05 23:04:00
 honesy
				 [专家分:90]  发布于 2008-01-05 23:04:00							
			求一颗二叉树的最大宽度~[color=FF0000]ffoooo[/color]
那位大侠给个思想,要求非递归的~
主要是在判断一层结束该怎么设计~~
						
					 
		
			
回复列表 (共2个回复)
		
								
				沙发
				
					 justforfun626 [专家分:18460]  发布于 2008-01-06 05:23:00
justforfun626 [专家分:18460]  发布于 2008-01-06 05:23:00				
				I believe you should know bread first search (BSF)
I guess one way to do it :
1) when you put the node in the queue, you also add an depth info and keep a depth count
2) when you change depth, remember the max of depth count
This is just a quick thought, you may have a better way to do it.
							 
						
				板凳
				
					 tysyjsj [专家分:800]  发布于 2008-01-06 14:04:00
tysyjsj [专家分:800]  发布于 2008-01-06 14:04:00				
				同意楼上的,广度优先遍历
							 
									
			
我来回复