-->
当前位置:首页 > 题库

PROGRAMMING:Tree level traversal

Luz5年前 (2021-05-10)题库475
We know that the left child of a node in a binary tree corresponds to the left child of a node in the tree, and the right child of a node in a binary tree corresponds to the right brother of a node in the tree. Then we can use the method of "Constructing Binary Tree Based on the first root sequence with null pointer information" to construct the left child right brother storage structure of the corresponding tree. As shown in Figure 1 (a), 8 5 10 6 0 2 0 3 4 0 7 0 0 0 0 0 0 0 corresponds to the tree as shown in Figure 1 (b).
![ tree.jpg](~/affb7ce1-4cb4-4b00-9612-84890cd945a1.jpg)
Please write a program to build the tree with the above method, and give the hierarchical traversal sequence of the tree.
###Input format:
The input is a group of integers separated by spaces, the number of which is not more than 100, indicating the first root sequence of binary tree with null pointer information. The null pointer information is represented by 0
###Output format:
The input is a group of integers, and a space after each integer represents the hierarchical traversal sequence of the tree.
###Input example:
```in
1 2 0 3 0 4 0 0 0
```
###Output example:
```out
1 2 3 4
```







answer:If there is no answer, please comment