树的先序遍历,异常结束
不会输出遍历的结果,直接程序崩溃,不知道为什么,求指点一下代码如下:
typedef char TElemType;
typedef struct BiTNode {
TElemType data;
struct BiTNode *left, *right;
}BiTNode, *BiTree;
void CreateBiTree(BiTree *T)
{
TElemType ch;
scanf_s("%c", &ch);
if (ch == '#')
*T = NULL;
else
{
*T = (BiTree)malloc(sizeof(BiTNode));
if (!*T)
return;
(*T)->data = ch;
CreateBiTree(&(*T)->left);
CreateBiTree(&(*T)->right);
}
}
void PreOrderTraverse(BiTree T)
{
if (T = NULL)
{
return;
}
printf("%c", T->data);
PreOrderTraverse(T->left);
PreOrderTraverse(T->right);
}
void main() {
BiTNode *T;
CreateBiTree(&T);
PreOrderTraverse(T);
}