#C14230. Binary Tree Level Order Traversal

    ID: 43857 Type: Default 1000ms 256MiB

Binary Tree Level Order Traversal

Binary Tree Level Order Traversal

Given the level order representation of a binary tree, where the token (\texttt{null}) represents a missing node, your task is to construct the binary tree and perform a level order (breadth-first) traversal. For each level of the tree, output the node values from left to right, with each level printed on a new line and values separated by a single space.

For example, the input:

3 9 20 null null 15 7

represents the binary tree:

[ 3
/ \ 9 20
/ \ 15 7 ]

and its level order traversal is:

3
9 20
15 7

You are required to read the input from standard input (stdin) and print the output to standard output (stdout).

inputFormat

The input is a single line containing space-separated tokens representing the binary tree in level order. Each token is either an integer or the literal (\texttt{null}), which denotes a missing child node.

Example:

3 9 20 null null 15 7

outputFormat

Output the level order traversal of the binary tree. Each level must be printed on a new line, and within each level the node values should be separated by a single space.

Example Output:

3
9 20
15 7## sample
3 9 20 null null 15 7
3

9 20 15 7

</p>