根据定理来说不需要建树,直接可输出
求先序遍历 洛谷P1030
题目描述
给出一棵二叉树的中序与后序排列。求出它的先序排列。(约定树结点用不同的大写字母表示,长度\le 8≤8)。
sample input
BADC
BDCA
sample output
ABCD
代码片
#include<bits/stdc++.h>
using namespace std;
string s1,s2; //s2记录中序遍历,s1记录后序遍历
int n;
void build(int x, int s, int e) {
for(int i=s; i<=e; i++ ) {
if ( s1[x]==s2[i] ) {
cout<<s1[x];
build(x-e+i-1,s