建树:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int maxn=35;
int InOrder[maxn],PostOrder[maxn];
struct Node{//定义树的左右两个子树
int r,l;
}a[maxn];
// 中序遍历[l1....l2]后序遍历[r1....r2]
int build(int l1,int l2,int r1,int r2){
if(l1>l2) return 0;//空树
int root = PostOrder[r2];//定义根节点
int p = l1;
while(InOrder[p] != root) p++;//寻找根节点
int cnt = p-l1;
a[root].l = build(l1,p-1,r1,r1+cnt-1);//建立左子树
a[root].r= build(p+1,l2,r1+cnt,r2-1);//建立右子树
return root;
}