Challenge: Print a Tree in Level-order Line by Line Using a Queue

Try solving the problem of printing the binary tree using level-order traversal. Check if you can implement the solution using one queue.

Problem

Given a binary tree, perform a level-order traversal on it by completing the PrintLevelOrderLineByLine2()function. Try to solve this problem using one queue this time. For more information about the level order traversal, refer to this lesson.

Input

A binary tree.

Output

Display the level-order traversal of the tree on the console.

Sample input

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.