看看先序创建,遍历二叉树哪错了,谢谢!?
#include<stdio.h>typedef char TElemType;
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild, *rchild;
}BiTNode, *BiTree;
/*递归创建一个二叉树*/
void createBiTree(BiTree t)
{
char c;
c = getchar();
if(c == 's')
{
t = NULL;
}
else
{
t = (BiTree)malloc(sizeof(BiTNode));
t -> data = c;
createBiTree(t -> lchild);
createBiTree(t -> rchild);
}
}
/*先序遍历二叉树*/
void preOrder(BiTree t)
{
if(t)
{
printf("%c", t -> data);
preOrder(t -> lchild);
preOrder(t -> rchild);
}
else
printf("this is a empty tree!");
}
int main()
{
BiTree t = NULL;
clrscr();
printf("create a tree:");
createBiTree(t);
printf("preOrder the tree:");
preOrder(t);
getch();
return 0;
}