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

PROGRAMMING:Playing with binary trees

Luz5年前 (2021-05-10)题库555
Given a binary tree in the order of traversal and preorder traversal, you first do a mirror tree inversion, and then output sequence traversal after inversion. The so-called mirror inversion is to exchange the left and right children of all non leaf nodes. Here we assume that the key values are all positive integers that are not equal to each other.
###Input format:
Enter the first line to give a positive integer 'n' ($$$Le $$30), which is the number of nodes in the binary tree. The second line gives the middle order traversal sequence. The third line gives its preorder traversal sequence. Numbers are separated by spaces.
###Output format:
Output the sequence traversed by the inverted sequence of the tree in one line. The numbers should be separated by one space, and there should be no extra space at the beginning and end of the line.
###Input example:
```in
seven
1 2 3 4 5 6 7
4 1 3 2 6 5 7
```
###Output example:
```out
4 6 1 7 5 3 2
```






answer:If there is no answer, please comment