谁能够帮咱编一段c语言程序,要求如下:创建二叉树,并遍历

来源:百度知道 编辑:UC知道 时间:2024/05/18 06:38:38
1)输入先中序唯一确定二叉树(2)打印输出层次遍历,先中后序遍历.小妹先谢谢了

创建 并 中序遍历输出

#include <stdio.h>
#include <malloc.h>
typedef enum{Link,Thread} PointerTag; //指针标志
typedef int DataType;
typedef struct BiThreTree{ //定义结点元素
PointerTag LTag,RTag;
DataType data;
struct BiThreTree *lchild,*rchild;
}BiThreTree;
BiThreTree *pre; //全局变量,用于二叉树的线索化
BiThreTree *CreateTree() //按前序输入建立二叉树
{
BiThreTree *T;
DataType e;
scanf("%d",&e);
if(e==0)
T=NULL;
else
{T=(BiThreTree *)malloc(sizeof(BiThreTree));
T->data=e;
T->LTag=Link; //初始化时指针标志均为Link
T->RTag=Link;
T->lchild=CreateTree();
T->rchild=CreateTree();
}
return T;
}
void InThread(BiThreTree *T)
{