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

PROGRAMMING:Pre-order to Post-order

Luz5年前 (2021-05-10)题库418
Given the pre-order traversal sequence of a binary tree with no one-degree nodes , you should output the post-order traversal sequence of this tree. It is guaranteed that all nodes' keys are positive and that only one result sequence can be obtained.
### Input Specification:
Each test file contains one test case. For each test case, an integer $$N$$ is given in the first line of input, which denotes the number of nodes in the binary tree. The next line contains the pre-order traversal sequence, which consists of $$N$$ integers. If an integer is negative, it belongs to a leaf node, whose value is still positive.
### Output Specification:
You should output the post-order traversal sequence in a line. The numbers in the sequence should be separated by a space, and no extra space is allowed at the end of line.
### Sample Input:
```in
seven
3 2 -1 -4 5 -7 -9
```
### Sample Output:
```out
1 4 2 7 9 5 3
```







answer:If there is no answer, please comment