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

PROGRAMMING:Traversal of binary tree

Luz5年前 (2021-05-10)题库372
The binary tree is constructed according to the input, and the precedence sequence of the binary tree is output. Binary tree has n nodes, node number is 1 to n. Node 1 is the root node.
###Input format:
Enter the integer n in the first line.
Next, there are n rows, giving the left child and the right child of nodes 1 to N in turn. For each of these n rows, there are two integers. In line I (I = 1, 2,..., n), the first integer indicates the number of the left child and the second integer indicates the number of the right child. If the integer value is 0, there is no left or right child.
###Output format:
Output a line, the content is the binary tree sequence. The node numbers are separated by spaces, and there is a space at the end of the line.
###Input example:
```in
six
2 5
3 4
0 0
0 0
0 6
0 0
```
###Output example:
```out
1 2 3 4 5 6
```







answer:If there is no answer, please comment