``````typedef struct tree{
char data;
struct tree *lc,*rc;
}BitNode,*BitTree;``````

1.采用层次遍历

``````bool JudgeComplete(BitTree root)
{
queue<BitTree> q;
if(NULL == root)
return true;
q.push(root);
BitTree cur = NULL;
bool flag = false;
while(!q.empty())
{
cur = q.front();
q.pop();
if(cur)
{
if(flag)
return false;
q.push(cur->lc);
q.push(cur->rc);
}
else
flag = true;
}
return true;
}
``````

2.递归判断的方法

``````bool JudgeComplete(BitTree root)
{
if(root != NULL){
if(root->rc != NULL && root->lc == NULL)
return false;
JudgeComplete(root->lc);
JudgeComplete(root->rc);
}
return true;
}``````

``````bool JudgeComplete(BitTree root)   //采用递归算法来实现判断是否为完全二叉树
{
if(root == NULL)
return   true;
if(root->lc == NULL && root->rc == NULL)
return   true;
if(root->lc  == NULL  && root->rc != NULL || root->lc != NULL && root->rc == NULL)
return   false;
return   JudgeComplete(root->lc) & JudgeComplete(root->rc);

}``````

原文作者：sean10
原文地址: https://www.cnblogs.com/sean10/p/5005184.html
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。