#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *lchild;
struct node *rchild;
}*Tree, Tnode; /* binary tree structure */
static void CreateTree(Tree *T);
static void VisitTree(Tree T);
int main(void)
{
Tree T = NULL;
CreateTree(&T); /* create binary tree */
VisitTree(T); /* inorder print binary tree */
printf("NULL\n");
return 0;
}
static void CreateTree(Tree *T)
{
int value;
scanf("%d", &value);
if (value == 0)
{
*T = NULL;
}
else
{
if (((*T) = (Tree)malloc(sizeof(Tnode))) == NULL)
{
exit(1);
}
(*T) -> data = value;
CreateTree(&(*T) -> lchild);
CreateTree(&(*T) -> rchild);
}
}
static void VisitTree(Tree T)
{
if (T != NULL)
{
VisitTree(T -> lchild);
printf("%d -> ", T -> data);
VisitTree(T -> rchild);
}
free(T); /* free memory */
}