A common problem in data structures is to determine the traversal ofa binary tree. There are three classic ways to do it:
Pre-order: You must visit insequence the root, left subtree and the right subtree.
In-order: You must visitin sequence the left subtree, the root and the right subtree.
Post-order: You must visit insequence the left subtree, the right subtree and the root.
See the picture below:
The pre, in and post-order traversal are, respectively, ABCDEF, CBAEDF and CBEFDA. In this problem, you must compute the post-ordertraversal of a binary tree given its in-order and pre-order traversals.
The input set consists of a positive number C ≤ 2000, thatgives the number of test cases and Clines, one for each test case. Each test case starts with a number 1≤ N≤ 52, the number of nodes in this binary tree. After, there will betwo strings S1 and S2 thatdescribe the pre-order and in-order traversal of the tree. Thenodes of the tree are labeled with different characters in the range a..zand A..Z. The values of N,S1 and S2 are separeted by a blankspace.
For each input set, you should output a line containing the post-ordertransversal for the current tree.
3 3 xYz Yxz 3 abc cba 6 ABCDEF CBAEDF
Yzx cba CBEFDAProblem setter: Sebastião Alves #include<iostream>
二叉树 的基本问题 注意下 recontruct 的算法 体会下 递归的函数 的使用,再者就是 输入输出的变换。。。灵活使用 。。。表示因为输入问题wa
了两次,后来 认识到不是算法的问题 ,改了下输入的方法就ac