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

PROGRAMMING:Traversal

Luz5年前 (2021-05-10)题库433
Keven encountered a big problem this time. The main idea of the topic is to give you a binary tree's preorder traversal and middle order traversal, and output its postorder traversal. It's hard to break Keven. Fortunately, Keven knows you, so he asked you about this problem.
###Input format:
The first line is a number, indicating the length of the preorder and mesorder sequences.
The second line is a string representing its preorder traversal sequence
The third line is a string representing its middle order traversal sequence.
Ensure that the string contains only uppercase letters and is not equal to each other
###Output format:
Output its postorder traversal on one line.
###Input example:
Here is a set of inputs. For example:
```in
four
ABCD
BACD
```
###Output example:
The corresponding output is given here. For example:
```out
BDCA
```
###Tips:
Preorder traversal is to visit the root node first, then the left child node, and finally the right child node in the binary tree
Middle order traversal is to visit the left child node first, then the root node, and finally the right child node in the binary tree
Postorder traversal is to visit the left child node first, then the right child node, and finally the root node in the binary tree
###Case diagram
![ Case diagram. PNG] (~ / 1d8ef32b-dbc3-49d5-bf30-9f26f7139f1a. PNG)







answer:If there is no answer, please comment