#includestdio.h #includemalloc.h typedef char dataType ; struct TreeNode { dataType data ; TreeNode * left , * right ; }; //创建二叉树 void CreateTree ( TreeNode * t , dataType x ){ dataType d ; scanf ( "%c " , d ); if ( d == x ){ t =
#include<stdio.h>
#include<malloc.h>
typedef char dataType;
struct TreeNode{
dataType data;
TreeNode *left,*right;
};
//创建二叉树
void CreateTree(TreeNode *&t,dataType x){
dataType d;
scanf("%c ",&d);
if(d == x){
t = NULL;
}else{
t = (TreeNode*)malloc(sizeof(TreeNode));
t->data = d;
CreateTree(t->left,x);
CreateTree(t->right,x);
}
}
//输出二叉树
void PrintTree(TreeNode *t){
if(t){
printf("%c ",t->data);
PrintTree(t->left);
PrintTree(t->right);
}
}
int main()
{
TreeNode *t;
printf("如输入ABD#G###CE##F##\n");
CreateTree(t,'#');
PrintTree(t);
}