# include & ltstdlib.h & gt
# include & ltmalloc.h & gt
#定義OK?1
#定義錯誤?0
#定義溢出?0
typedef char TElemType
typedef int狀態;
typedef結構位節點
{
遙測數據;
struct BiTNode *lchild,* rchild
}BiTNode,* BiTree
typedef枚舉{Link,Thread } PointerTag
typedef結構BiThrNode
{
遙測數據;
struct BiThrNode *lchild,* rchild
指針標簽LTag,RTag
} BiThrNode
typedef BiThrNode * BiThrTree
BiTree CreateBiTree(BiTree T)?//壹階遍歷構造二叉樹
{
char ch
scanf("%c ",& ampch);
if(ch=='# ')?//#代表空指針。
T = NULL
其他
{
t =(bit node *)malloc(sizeof(bit node));?//應用程序節點
如果(!t)
退出(溢出);
t->;數據= ch?//生成根節點
t->;l child = create bitree(T-& gt;l child);?//構造左邊的子樹
t->;rchild = create bitree(T-& gt;rchild);?//構造右邊的子樹
}
return T;
}
Status InOrderTraverse(BiTree T,Status(* visit)(teletype))
{//二叉樹的中序遍歷
如果(T)
{
if(in order traverse(T-& gt;lchild,訪問))
如果(訪問(T-& gt;數據))
if(in order traverse(T-& gt;兒童,訪問))
退貨OK;
返回錯誤;
}
其他
退貨OK;
}
狀態打印元素(遠程類型e)
{
printf("%-2c ",e);
退貨OK;
}
void main()
{
BiTree T = NULL
Printf("請輸入構造二叉樹的字符序列:");
T = create bitree(T);
如果(T)
Printf("二叉樹建立成功!\ n ");
其他
Printf("二叉樹構造失敗!!!\ n ");
Printf("中序遍歷二叉樹:");
InOrderTraverse(T,print element);
printf(" \ n ");
}