标签:char create == post highlight return sha arp 构造
中序先序构造
BTNode* CreateBT(char* pre, char* in, int n) { char* p; BTNode* b; int k; if (n <= 0) return NULL; b = (BTNode*)malloc(sizeof(BTNode)); b->data = *pre; for (p = in; p < in + n; p++) { if (*p == *pre) break; } k = p - in; b->lchild = CreateBT(pre+1, in, k); b->rchild = CreateBT(pre + k + 1, p+1, n - k - 1); return b; }
中序后序构造
BTNode* CreateBT2(char* in, char* post, int n) { int k; char* p; BTNode* b = (BTNode*)malloc(sizeof(BTNode)); if (n <= 0) return NULL; b->data = *(post + n - 1); for (p = in; p < in + n; p++) { if (*p == *(post + n - 1)) break; } k = p - in; b->lchild = CreateBT2(in, post, k); b->rchild = CreateBT2(p + 1, post + k, n - k - 1); return b; }
标签:char create == post highlight return sha arp 构造
原文地址:https://www.cnblogs.com/KIROsola/p/11440002.html