#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode, *BiTree;
void CreateBiTree(BiTree *T)
{
char c;
scanf("%c",&c);
if(c=='#'){
*T=NULL;}
else{
*T=(BiTNode*)malloc(sizeof(BiTNode));
(*T)->data=c;
CreateBiTree(&((*T)->lchild));
CreateBiTree(&((*T)->rchild));
}
}
void InOrderTraverse(BiTree T)
{
if(T)
{
InOrderTraverse(T->lchild);
printf("%c",T->data);
InOrderTraverse(T->rchild);
}
}
void PostOrderTravese(BiTree T)
{
if(T)
{
PostOrderTravese(T->lchild);
PostOrderTravese(T->rchild);
printf("%c",T->data);
}
}
int RegularBiTree(BiTree T)
{
if(T->lchild&&T->rchild)
{
RegularBiTree(T->lchild);
RegularBiTree(T->rchild);
}
else if((T->lchild==NULL)&&(T->rchild==NULL))
{
return 1;
}
else
return 0;
}
void main(){
BiTree T=NULL;
CreateBiTree(&T);
printf("中序遍历为:
");
InOrderTraverse(T);
printf("
");
printf("后序遍历为:
");
PostOrderTravese(T);
printf("
");
RegularBiTree(T);
if(RegularBiTree(T))
printf("该二叉树是正则二叉树");
else
printf("该二叉树不是正则二叉树");
}