#C2505. Binary Tree Level Order Traversal
Binary Tree Level Order Traversal
Binary Tree Level Order Traversal
Given a binary tree, perform a level order traversal (also known as Breadth-First Search) on the tree. In a level order traversal, you visit the nodes level by level from left to right.
The binary tree is provided in a serialized format as a single line of input in level order where missing nodes are denoted by the token null
. For example, the tree
(
1
/
2 3
/ \ /
4 5 6 7
)
is given as:
1 2 3 4 5 6 7
If the tree is empty, the input will be an empty string.
Your task is to construct the binary tree from the input and output its level order traversal as a sequence of values separated by a single space.
inputFormat
The input is provided as a single line read from stdin containing the level order serialization of the binary tree. Nodes are separated by spaces. Null nodes are represented by the token null
. For example:
1 2 3 4 5 6 7
An empty input indicates an empty tree.
outputFormat
Output the level order traversal of the tree as a sequence of integers separated by a single space. The output should be printed to stdout. For an empty tree, output nothing.
## sample1 2 3 4 5 6 7
1 2 3 4 5 6 7