二叉树的输入和输出

#include <stdio.h>

#include <stdlib.h>

typedef struct tree{  

  char data;  

  struct tree *ltree,*rtree;

}Tree;

Tree * createTree(Tree *T){  

   char n;    

T=(Tree *)malloc(sizeof(Tree));

 scanf("%c",&n);

 if(n=='#'){   T=NULL;

 }  

else{

  T->data=n;

  T->ltree=createTree(T->ltree);  

 T->rtree=createTree(T->rtree);  

}  

  return T;  

    }

void printTree(Tree *T){

 if(T!=NULL){

 printf("%c",T->data); 

 printTree(T->ltree);

 printTree(T->rtree);

   }

}

int main(){  

Tree *T;

T=createTree(T);

printTree(T);

return 0; }

猜你喜欢

转载自www.cnblogs.com/ljxn/p/10726372.html