求大神指导,我不知道这visit函数怎么啦
/*创建二叉树:先序创建;遍历二叉树:先,中,后;
二叉树属性:深度,结点数,叶子结点数;
*/
#include<stdio.h>
#include<malloc.h>
typedef char DataType;
typedef struct BNode
{
char data;
struct BNode *Lchild;
struct BNode *Rchild;
}BNode,*BiTree;
void CreateTree(BiTree &T)
{
char ch;
scanf("%c",&ch); //读入一个字符
if(ch==' ') T=NULL;
else{T=(BNode *)malloc(sizeof(BNode)); //生成一个新结点
T->data=ch;
CreateTree(T->Lchild); //生成左子树
CreateTree(T->Rchild); //生成右子树
}
}
void visit(BiTree root)
{
if(root!=NULL)
printf("%c",root->data);
}
void PreOrder(BiTree root)
{if(root!=NULL)
{
visit(root->data);
PreOrder(root->Lchild);
PreOrder(root->Rchild);
}
}
void InOrder(BiTree root)
{if(root!=NULL)
{
InOrder(root->Lchild);
visit(root->data);
InOrder(root->Rchild);
}
}
void PostOrder(BiTree root)
{if(root!=NULL)
{
PostOrder(root->Lchild);
PostOrder(root->Rchild);
visit(root->data);
}
}
int PostTreeDepth(BiTree bt)
{
int h1,h2,max;
if(bt!=NULL)
{
h1=PostTreeDepth(bt->Lchild);
h2=PostTreeDepth(bt->Rchild);
max=h1>h2?h1:h2;
return(max+1);
}
else return(0);
}
int TreeCount(BiTree root)
{
int Count;
if(root==NULL) return(0);
else
Count=TreeCount(root->Lchild)+TreeCount(root->Rchild)+1;
return(Count);
}
int leaf(BiTree root)
{
int LeafCount;
if(root==NULL)
LeafCount=0;
else if((root->Lchild==NULL)&&(root->Rchild==NULL))
LeafCount=1;
LeafCount=leaf(root->Lchild)+leaf(root->Rchild);
return(LeafCount);
}
void main()
{
BiTree T;
char j;
int flag=1;
//---------------------程序解说-----------------------
printf("本程序实现二叉树的操作。\n");
printf("可以进行建立二叉树;递归先序、中序、后序遍历;二叉树属性:深度,结点数,叶子结点数\n");
//----------------------------------------------------
printf("\n");
printf("请建立二叉树。\n");
CreateTree(T);
getchar();
while(flag)
{
printf("\n");
printf("请选择: \n");
printf("1.递归先序遍历\n");
printf("2.递归中序遍历\n");
printf("3.递归后序遍历\n");
printf("4.二叉树深度\n");
printf("5.二叉树结点数\n");
printf("6.二叉树叶子结点数\n");
printf("0.退出程序\n");
scanf(" %c",&j);
switch(j)
{
case '1':if(T)
{ printf("递归先序遍历二叉树:");
PreOrder(T);
printf("\n");
}
else
printf("二叉树为空!\n");
break;
case '2':if(T)
{
printf("递归中序遍历二叉树:");
InOrder(T);
printf("\n");
}
else
printf("二叉树为空!\n");
break;
case '3':if(T)
{ printf("递归后序遍历二叉树:");
PostOrder(T);
printf("\n");
}
else
printf("二叉树为空!\n");
break;
case '4':if(T)
{
printf("二叉树深度:");
PostTreeDepth(T);
printf("\n");
}
else
printf("二叉树为空!\n");
break;
case '5':if(T)
{
printf("二叉树结点数:");
TreeCount(T);
printf("\n");
}
else printf("二叉树为空!\n");
break;
case '6':if(T)
{
printf("二叉树叶子结点数:");
leaf(T);
printf("\n");
}
else printf("二叉树为空!\n");
break;
default:flag=0;printf("程序运行结束,按任意键退出!\n");
}
}
}