编辑代码

#include<stdio.h>
#include<stdlib.h>
typedef char Etype;
typedef struct BiTNode
{
 Etype data;
 struct BiTNode *lch,*rch;
}BiTNode,*BiTree;
BiTNode *t;
BiTNode *creat_bt2();
void preorder(BiTNode *p);
void inorder(BiTNode *p);
void postorder(BiTNode *p);
/*main start*/
void main()
{
 printf("create the bittree\n");
 printf("\n please enter value of each item:\n");
 fflush(stdin);
 t=creat_bt2();
 if(t)
 {
  printf("preorder:\n");
  preorder(t);
  printf("\n");
 }
 else
  printf("the bittree is null\n");

 if(t)
 {
  printf("inorder:\n");
  inorder(t);
  printf("\n");
 }
  else
 printf("the bittree is null\n");

  if(t)
 {
  printf("postorder:\n");
  postorder(t);
  printf("\n");
 }
  else
   printf("the bittree is null\n");
   getchar();
}
/*main over*/

 BiTNode * creat_bt2()
 {
  BiTNode *t; Etype e;
  scanf("%c",&e);
  if(e=='#') t=NULL;
  else{
       t=(BiTNode *)malloc(sizeof(BiTNode));
       t->data=e;
       t->lch=creat_bt2();
       t->rch=creat_bt2();
       }
      return(t);
 }

 void preorder(BiTNode *p)
 {
  if(p){
   printf("%3c",p->data);
   preorder(p->lch);
   preorder(p->rch);
  }
 }

 void inorder(BiTNode *p)
 {
   if(p){
	   inorder(p->lch);
	   printf("%3c",p->data);
	   inorder(p->rch);
  }                      /*请自行将此模块补充完整*/
 }

 void postorder(BiTNode *p)
 {
	if(p){
	   postorder(p->lch);
	   postorder(p->rch);
	   printf("%3c",p->data);
  } 
                              /*请自行将此模块补充完整*/
 }