二叉树的建立和中序遍历
#include <stdio.h>#include <stdlib.h>
typedef struct BiTNode
{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
int InitBiTree(BiTree t)
{
t=NULL;
return 1;
}
void CreateBiTree(BiTree t)
{int ch;
printf("请输入数据:");
scanf("%d",&ch);
if(ch==0)
t=NULL;
else
{
t=(BiTree)malloc(sizeof(BiTNode));
t->data=ch;
CreateBiTree(t->lchild);
CreateBiTree(t->rchild);
}
}
int visitT(int e)
{
printf("%4d",e);
}
void PreOrderPrint(BiTree t)
{
if(t)
{
visitT(t->data);
PreOrderPrint(t->lchild);
PreOrderPrint(t->rchild);
}
}
main()
{BiTree p;
InitBiTree(p);
CreateBiTree(p);
PreOrderPrint(p);
}
运行后输出时乱码,请高手们帮忙改一下……