有两种方法
一种是算数:根据深度对比结点数
另一种是根据二叉树树型:结点的左右子树深度一样 并且 其左右子树必须成双或者无左右子树 即为满二叉树(有代码)
#include <stdio.h>
#include <stdlib.h>
typedef char ElemType;
typedef struct BNode
{
ElemType data;
struct BNode *lchild;
struct BNode *rchild;
}BTNode;
typedef BTNode* BinTree;
/*创建二叉树*/
void CreateBinTree(BinTree &root)
{
char i;
if((i=getchar())=='#')
root=NULL; //建立空结点
else
{
root=(BTNode*)malloc(sizeof(BTNode));
root->data=i;
CreateBinTree(root->lchild);
CreateBinTree(root->rchild);
}
}
//判断左右深度是否相同
int Height(BinTree root)
{
int h,lh,rh;
if(root==NULL)return 0;
return Height(root->lchild)>Height(root->rchild)?Height(root->lchild)+1:Height(root->rchild)+1;
}
//子树满或子树全空是返回值为0
int Full(BinTree root)
{
if(root ==NULL) return 0;
if((root->lchild)==NULL&&(root->rchild)