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

PROGRAMMING:Reconstruction of binary tree

Luz5年前 (2021-05-10)题库418
Two strings are given to represent the results of preorder traversal (root, left subtree, right subtree) and middle order traversal (left subtree, root, right subtree) of binary tree< br/>
For example, for the following binary tree, the preorder traversal result is dbacgf, and the meso traversal result is ABCDEFG< br/>
![ binary_ tree.jpg](~/45e1d5f0-d36e-4fbf-a4b6-617e06743837.jpg)


It is assumed that every node of a binary tree is identified with uppercase letters, and the same letter will not be used twice for the same binary tree. Now, please reconstruct this binary tree according to the given preorder traversal and middle order traversal.
###Input format:
The input contains one or more test cases. One line for each test case, two strings are given to show the results of preorder traversal and middle order traversal of binary tree. Both strings are made up of uppercase letters (so they are no longer than 26).
###Output format:
Each test case is transformed into a binary tree, and the results of the subsequent traversal (left subtree, right subtree, root) of the tree are output in a row.
###Input example:
```in
DBACEGF ABCDEFG
BCAD CBAD
```
###Output example:
```out
ACBFGED
CDAB
```







answer:If there is no answer, please comment