#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;
扫描二维码关注公众号,回复:
5926901 查看本文章
}
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; }