// known sequence preorder and establishing a binary tree void CreateTree (BTTree T, int [] pre, int [] in , int L1, int h1 of, int L2, int H2) { // L1 sequence for the first array first, h1 is the last first sequence array int I; T = (BTNode *) the malloc ( the sizeof (BTNode)); T -> Data pre = [L1]; // root for (I = L2; I < H2 =; I ++ ) { IF (pre [L1] == in [I]) BREAK ; } IF (I == L2) T-> lchild = null; else{ CreateTree(t->lchild,pre,in,l1+1,l1+i-l2,l2,i-1); } if(i==h2) T->rchild=null; else{ CreateTree(T->rchild,pre,in,l1+i-l2+1,h1,i+1,h2); } }
[Binary tree algorithm] known preorder and inorder to establish a binary tree
Guess you like
Origin www.cnblogs.com/zzuuoo666/p/12083183.html
Recommended
Ranking