标签:div create inode 序列 har roo log style amp
1 void PreInOrd(char preord[], char inord[], int j, int j, int k, int h, BiTree *t) 2 { 3 //先序序列:i->j,中序序列k->h,建立二叉树t 4 int m; 5 (*t) = new BiNode; 6 (*t)->data = preord[i]; 7 m = k; 8 while (inord[m] != preord[i]) 9 { 10 m++; 11 } 12 if (m == k) 13 { 14 //左子树空 15 (*t)->lchild = NULL; 16 } 17 else 18 { 19 PreInOrd(preord, inord, i + 1, i + m - k, k, m - 1, &((*t)->lchild)); 20 } 21 if (m == h) 22 { 23 //右子树空 24 (*t)->rchild = NULL; 25 } 26 else 27 { 28 PreInOrd(preord, inord, i + m - k + 1, j, m + 1, h, &((*t)->lchild)); 29 } 30 } 31 32 void CreateBiTree(char preord[], char inord[], int n, BiTree root) 33 { 34 if (n <= 0) 35 { 36 root = NULL; 37 } 38 else 39 { 40 PreInOrd(preord, inord, 1, n, 1, n, &root); 41 } 42 }
标签:div create inode 序列 har roo log style amp
原文地址:http://www.cnblogs.com/ldzhangyx/p/6127784.html