标签:
直接上代码了
struct BTNode { int val; BTNode *lchild; BTNode *rchild; BTNode(int x): val(x), lchild(NULL), rchild(NULL){} }; BTNode* rebuildBinTree(int a[], int b[], int n) { if (n <= 0) return NULL; BTNode *root = new BTNode(a[0]); int i; for (i = 0; i < n; ++i) { if (b[i] == a[0]) break; } root->lchild = rebuildBinTree(a+1, b, i); root->rchild = rebuildBinTree(a+i+1, b+i+1,n-i-1); return root; }
对应文章:http://www.cnblogs.com/youxin/p/3288261.html
标签:
原文地址:http://www.cnblogs.com/gattaca/p/4649419.html