求大神教如何输入树
#include<stdio.h>#include<malloc.h>
#include<stdlib.h>
typedef char DataType;
typedef struct BitNode
{DataType data;
struct BitNode *lchild,*rchild;
}BitNode,*BitTree;
void BinTreeInit(BitTree *BT) /*初始化二叉树树根指针置空*/
{
BT=NULL;
}
void BinTreeCreat(BitTree BT)/*按先序建立一个二叉树*/
{
char ch;
scanf(&ch);
if(ch==' ') BT=NULL;
else{
BT=((BitNode *)malloc(sizeof(BitNode)));
BT->data=ch;
BinTreeCreat(BT->lchild);
BinTreeCreat(BT->rchild);
}
}
int BinTreeEmpty(BitTree BT)/*检查二叉树是否为空*/
{
if(BT==NULL)
printf("是空二叉树");
else
printf("不是二叉树");
}
void BinTraverse(BitTree BT) /先序遍历二叉树*/
{
if(BT!=NULL)
{
printf("%d",BT->data);
BinTraverse(BT->lchild);
BinTraverse(BT->rchild);
}
}
int BinTreeDepth(BitTree BT) /*求二叉树的深度*/
{
int i;
if(BT)
{
int dethl=BinTreeDepth(BT->lchild);
int dethr=BinTreeDepth(BT->rchild);
i=1+(dethl>dethr?dethl:dethr);
}
else i=0;
return i;
}
int BinTreeCount(BitTree BT)/*求二叉树中所有结点数*/
{
int node;
if(BT)
{
int m=BinTreeCount(BT->lchild);
int n=BinTreeCount(BT->rchild);
node=m+n+1;
}
else
node=0;
return node;
}
void BinTreeClear(BitTree BT)/*清除二叉树变为空树*/
{
if(BT!=NULL)
{
BT->lchild=NULL;
BT->rchild=NULL;
BT=NULL;
}
}
int main()
{
BitTree *BT;
void BinTreeCreat(BitTree BT);
void BinTreeInit(BitTree *BT);
int BinTreeEmpty(BitTree BT);
void BinTraverse1(BitTree BT);
int BinTreeDepth(BitTree BT);
int BinTreeCount(BitTree BT);
void BinTreeClear(BitTree BT);
return 0;
}