标题:二叉树的判断
只看楼主
jiejiao268
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-4-25
 问题点数:0 回复次数:0 
二叉树的判断
二叉树怎么判断是否为完全二叉树啊
#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;
}
搜索更多相关主题的帖子: include return 二叉树 
2016-04-25 21:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464112-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.442302 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved