#include <cstdio> #include <iostream> using namespace std; const int N = 50; int pre[N], in[N], post[N]; int n; struct node { int data; node* lchild; node* rchild; }; node* create(int prel, int prer, int inl, int inr) { if (prel>prer) { return NULL; } node* root = new node; root->data = pre[prel]; int k; for (k = inl; k <= inr; k++) { if (in[k] == pre[prel]) break; } int numleft = k - inl; root->lchild = create(prel + 1, prel + numleft, inl, k - 1); root->rchild = create(prel + numleft + 1, prer, k + 1, inr); return root; }