二叉树的先序构造和显示,数据结构,构造出了问题,可以帮忙看看吗?
构造一直无法结束。。。。。。#include<stdio.h>
#include<stdlib.h>
#define MAX_TREE_SiZE 100
#define TURE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef char TElemType;
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode;//二叉树
typedef struct BiTNode *BiTree;
void CreatBiTree(BiTree *T);
void PreOrderTraverse(BiTree T,Status(*Visit)(TElemType));
Status PrintElement(TElemType e);
int main()
{
BiTree T;
printf("先序输入二叉树:");
CreatBiTree(&T);
printf("先序输出二叉树:");
PreOrderTraverse(T,PrintElement);
return 0;
}
void CreatBiTree(BiTree *T)
{//先需输入二叉树
char ch;
scanf("%c",&ch);
if(ch=='#')
*T=NULL;
else
{
(*T)=(BiTNode *)malloc(sizeof(BiTNode));
if(!*T)
exit(OVERFLOW);
(*T)->data=ch;
CreatBiTree(&(*T)->lchild);
CreatBiTree(&(*T)->rchild);
}
}
void PreOrderTraverse(BiTree T,Status(*Visit)(TElemType))
{//先序遍历二叉树,递归算法
if(T)
{
Visit(T->data);
PreOrderTraverse(T->lchild,Visit);
PreOrderTraverse(T->rchild,Visit);
}
}
Status PrintElement(TElemType e)
{
printf("%c ",e);
return OK;
}