搜索此博客

2011年2月28日星期一

Printing BFS (Binary Tree) in Level Order

Solution 1: iterative


First of all, we implement this function PrintNodeAtLevel




Then, we can travel all the level of the tree




The problem of the first solution is that it repeat traveling the tree from the root every time. To avoid the repeat computation, we can use an queue to put the nodes into the queue one by one.

没有评论:

发表评论