L2-006树的遍历(C语言)
#include
#include
struct tree
{
int data;
struct tree* lchild;
struct tree* rchild;
};
//建立树的结构体
struct tree *creat(int arr[], int brr[], int n)
{
if (n == 0)
{
return NULL;
}
int i = 0;
while (brr[i] != arr[n - 1])
{
i++;
}
int rn = n - 1 - i;
int ln = i;
struct tree* t = (struct tree*)malloc(sizeof(struct tree));
t->data = brr[i];
t->lchild = creat(&arr[0], &brr[0], ln);
t->rchild = creat(&arr[ln ], &brr[ln+1], rn);
共有 0 条评论