已知 前序和中序遍历 求后序遍历序列
struct node *creat(char *a, char *b, int n) { struct node *ptr; char *p; int count = 0; if (n <= 0) return NULL; ptr = (struct node *)malloc(sizeof(struct node)); ptr -> data = *a; for (p = &b[0]; p <= b + n - 1;p ++) { if (*p == *a) break; } count = p - b; ptr -> l = creat(a + 1, b, count); ptr -> r = creat(a + 1 + count, p + 1, n - 1 - count); return ptr; }已知中序和后序遍历 求前序遍历序列
struct node *creat(char *a, char *b, int n) { struct node *ptr; if (n <= 0) return NULL; ptr = (struct node *)malloc(sizeof(struct node)); ptr -> data = b[n - 1]; int q = strchr(a, b[n - 1]) - a; ptr -> l = creat(a, b, q); ptr -> r = creat(a + q + 1, b + q, n - q - 1); return ptr; }新闻热点
疑难解答