![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
//建二叉树与树的中序遍历
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
struct Bitree
{
char data;
struct Bitree *lchild,*rchild;
};
struct Bitree *CreateTree(struct Bitree *T)
{
char ch;
printf("input root:\n");
scanf("%c",&ch);
getchar();//接受回车
if(ch==' ')
T=NULL;//输入的是空格
else
{
T=(struct Bitree *)malloc(sizeof(Bitree));
if(!T)
exit(OVERFLOW);
T->data=ch;
T->lchild=CreateTree(T->lchild);
printf("input rchild:\n");
T->rchild=CreateTree(T->rchild);
}
return T;
}
int InOrderTree(struct Bitree *T)
{
if(T)
{
printf("%c\n",T->data);
PreOrderTree(T->lchild);
PreOrderTree(T->rchild);
return OK;
}
return ERROR;
}
int main()
{
struct Bitree *T;
T=CreateTree(T);
InOrderTree(T);
return 0;
}
![](https://www.cnblogs.com/Emoticons/baimantou/201937519.gif)
![](https://www.cnblogs.com/Emoticons/baimantou/201937519.gif)
![](https://www.cnblogs.com/Emoticons/baimantou/201937519.gif)