函数体
T为输入的二叉树,n为节点个数
bool Judge(BSTree &T,int n)//判断是否为完全二叉树
{
queue<BSTree> Q;
if(T==NULL)
return true;
else
{
int Count=0;//计算访问了几个结点
Q.push(T);
BSTree t;
while((t=Q.front())!=NULL)//当出现“空洞”时退出循环
{
Q.push(t->Left);
Q.push(t->Right);
Q.pop();
Count++;
}
if(Count==n)
return true;
else
return false;
}
}