//二叉树的二叉链表节点结构定义
typedef char TElemType;
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild, Rchild;
}BiTNode, *BiTree;
//前序遍历
void PreOrderTraverse(BiTree T)
{
if(T ==NULL)
{
return;
}
printf("%2c", T->data);
PreOrderTraverse(T->lchild); //先遍历左子树
PreOrderTraverse(T->Rchild); //最后遍历右子树
}
void InOrderTraverse(BiTree T)
{
if(T == NULL)
return;
InOrderTraverse(T->lchild);
printf("%2c", T->data);
InOrderTraverse(T->Rchild);
}
void PostOrderTraverse(BiTree T)
{
if(T== NULL)
return ;
PostOrderTraverse(T->lchild);
PostOrderTraverse(T->Rchild);
printf("%2c", T->data);
}
int FindTreeDeep(BiTree T){
int deep=0;
if(BT){
int lchilddeep=FindTreeDeep(T->lchild);
int rchilddeep=FindTreeDeep(T->rchild);
deep=lchilddeep>=rchilddeep?lchilddeep+1:rchilddeep+1;
}
return deep;
}
void CreateBiTree(BiTree *T)
{
TElemType ch;
scanf("%c", &ch);
if(ch == '#')
{
*T= NULL;
}
else
{
*T = (BiTree)malloc(sizeof](BiTNode));
if(!*T)
exit(-1);
(*T)->data = ch;
CreateBiTree(T->lchild);
CreateBiTree(T->Rchild);
}
}