问题链接
ALDS1_7_D:Reconstruction of a Tree
问题内容
给出前序数组和中序数组,求后序数组
思路
在当前前序数组的第一个元素pre[pos++],找出它在中序数组的下标m,然后根据中序数组的性质(左、根、右遍历的性质)分出左子树和右子树,所以进行递归下去求左右子树的根,最后根据后序数组的性质(左、右、根)可以直接存到post数组。
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace