关于二叉树的递归创建
#include <stdio.h>#include <stdlib.h>
//定义二叉树
typedef char ElemType;
typedef struct BiTNode{
ElemType data;
struct BiTNode *lchild,*rchild;
}BTree;
//创建一棵二叉树
void CreateBT(BTree *bt){
char ch;
scanf("%c",&ch);
if(ch=='#') bt=NULL;
else{
bt=(BTree *)malloc(sizeof(BTree));
bt->data=ch;
CreateBT(bt->lchild);
CreateBT(bt->rchild);
}
}
//先序遍历二叉树
void PreOrder(BTree *bt){
if(bt!=NULL){
printf("%c",bt->data);
PreOrder(bt->lchild);
PreOrder(bt->rchild);
}
}
int main() {
BTree *bt;
//建立一棵二叉树
printf("按前序序列输入一棵二叉树;\n");
CreateBT(bt);
//先序遍历二叉树
printf("前序遍历二叉树:\n");
PreOrder(bt);
return 0;
}
编译过了,运行不了,求大神指点