# include <stdio.h>
typedef struct node
{ char data;
struct node *lchild,*rchild;
} BTNode;
#define NodeLen sizeof(BTNode)
BTNode *t;
main()
{ BTNode *creat_bintree(BTNode *t);
void visit(BTNode *t);
void preorder(BTNode *t );
void inorder(BTNode *t );
void postorder(BTNode *t );
t=creat_bintree(t);
if (t)
{ printf("\n after preorder:\n"); preorder(t);
printf("\n after inorder:\n"); inorder(t);
printf("\n after postorder:\n"); postorder(t);
}
}
BTNode *creat_bintree(BTNode *t)
{ char ch;
printf("\n enter ch in preorder, 1 for no child:");
ch=getchar(); getchar();
if ( ch=='@') t=NULL;
else { t = (BTNode *)malloc(NodeLen);
t->data=ch;
t->lchild = creat_bintree( t->lchild );
t->rchild = creat_bintree( t->rchild );
}
return(t);
}
void visit(BTNode *t)
{ putchar(t->data);
printf("\t");
}
/* preorder_tree() */
void preorder(BTNode *t )
{ if (t)
{ visit(t);
preorder(t->lchild);
preorder(t->rchild);
}
}
/* inorder_tree() */
void inorder(BTNode *t )
{ if (t)
{ inorder(t->lchild);
visit(t);
inorder(t->rchild);
}
}
/* postorder_tree() */
void postorder(BTNode *t )
{ if (t)
{ postorder(t->lchild);
postorder(t->rchild);
visit(t);
}
}