#include "stdio.h"
#include "malloc.h"
int count;
typedef struct node
{
char data;
struct node *LChild;
struct node *RChild;
}BiTNode,*BiTree;
void creatbitree(BiTree * bt) // 先序便历序列创建二叉树链表
{
char ch=getchar();
if (ch=='#')
{
*bt=NULL;
}
else
{
*bt=(BiTree)malloc(sizeof(BiTNode));
(*bt)->data=ch;
creatbitree(&((*bt)->LChild));
creatbitree(&((*bt)->RChild));
}
}
int ProOrder(BiTree root) // 先序便历输出二叉树节点
{
if (root!=NULL)
{
printf("%c ",root->data); // 输出根节点
count++;
ProOrder(root->LChild);
ProOrder(root->RChild);
}
return count;
}
int PostTreeDepth(BiTree bt) // 后序便历求二叉树的高度
{
int hl,hr,max;
if (bt!=NULL)
{
hl=PostTreeDepth(bt->LChild);
hl=PostTreeDepth(bt->LChild);
max=hl>hr?hl:hr ;
return (max+1) ;
}
else
return 0;
}
void Judgment(int m,int n) // 判断该二叉树是否为满二叉树
{
int s=1;
for (int i=1;i<=n;i++)
{
s=s*2;
}
if (s-1==m)
{
printf("是满二叉树!
");
}
else
{
printf("不是满二叉树!
");
}
}
void main()
{
int c,h;
count=0;
BiTree root;
creatbitree(&root);
c=ProOrder(root);
h=PostTreeDepth(root);
printf("节点的总数:%d
",count);
printf("二叉树的深度:%d
",h);
Judgment(c,h);
}
原CSDN链接地址:http://blog.csdn.net/sha_520/article/details/7397534