How would you print out the data in a binary tree, level by level, starting at the top?
问题 This is an interview question I think of a solution. It uses queue. public Void BFS() { Queue q = new Queue(); q.Enqueue(root); Console.WriteLine(root.Value); while (q.count > 0) { Node n = q.DeQueue(); if (n.left !=null) { Console.Writeln(n.left); q.EnQueue(n.left); } if (n.right !=null) { Console.Writeln(n.right); q.EnQueue(n.right); } } } Can anything think of better solution than this, which doesn't use Queue? 回答1: Level by level traversal is known as Breadth-first traversal. Using a