注册 登录
编程论坛 VC++/MFC

二叉树的判断

jiejiao268 发布于 2016-04-25 21:22, 3998 次点击
二叉树怎么判断是否为完全二叉树啊
#include<iostream.h>
#include"BTNode.h"
#include"queue.h"
template<class T>
BTNode<T> * GetBTNode(const T & item,BTNode<T> * lp=NULL,BTNode<T> *rp=NULL)
{
    BTNode<T> *p;
    p=new BTNode<T>(item,lp,rp);
    if(p==NULL)
    {
        cout<<"创建失败"<<endl;
        exit(1);
    }
    return p;
}
template<class T>
void level(const BTNode<T> *t)
{
    if(t==NULL)
        return;
        Queue<const BTNode<T>*>Q;
        Q.Push(t);
        while(!Q.Empty())
        {
            t=Q.Pop();
            cout<<t->data;
            if(t->left)
                Q.Push(t->left);
            if(t->right)
                Q.Push(t->right);
        }
   
}
void main()
{
    BTNode<char> *nullp=NULL;
    BTNode<char> *fp=GetBTNode('F');
    BTNode<char> *dp=GetBTNode('D',fp);
    BTNode<char> *bp=GetBTNode('B',nullp,dp);
    BTNode<char> *ep=GetBTNode('E');
    BTNode<char> *cp=GetBTNode('C',nullp,ep);
    BTNode<char> *ap=GetBTNode('A',bp,cp);
    //level(ap);
    judge(ap);
    cout<<endl;
}
0 回复
1