二叉链表存储的二叉树

时间:2021-12-04 17:29:14

网址:http://zju.acmclub.com/index.php?app=problem_title&id=1&problem_id=1757

非常非常简单:

#include<stdio.h>#include<malloc.h>

typedef struct node
{
char data;
node *Lchild;
node *Rchild;
}Tree;

void CreateTree(Tree *&T)
{
char key;
scanf("%c",&key);
if(key == ' ')
{
T = NULL;
}
else
{
T = (Tree *)malloc(sizeof(Tree));
T->data = key;
CreateTree(T->Lchild);
CreateTree(T->Rchild);
}
}

void Pre(Tree *T)
{
if(T != NULL)
{
printf("%c ",T->data);
Pre(T->Lchild);
Pre(T->Rchild);
}
}

void Mid(Tree *T)
{
if(T != NULL)
{
Mid(T->Lchild);
printf("%c ",T->data);
Mid(T->Rchild);
}
}

int main()
{
Tree *T;
CreateTree(T);
Pre(T);
printf("\n");
Mid(T);
printf("\n");
Mid(T);
printf("\n");
return 0;
}


本文出自 “崛起_dj&lj” 博客,请务必保留此出处http://20111564.blog.51cto.com/6048168/1418702