| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 641 人关注过本帖
标题:【求助】帮我看看这段二叉树层次遍历代码哪里出错了
只看楼主 加入收藏
jingfeng_vae
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-8-6
收藏
 问题点数:0 回复次数:0 
【求助】帮我看看这段二叉树层次遍历代码哪里出错了
#include<iostream>
#define MAX_Queue_SIZE 1000
using namespace std;
typedef struct  BiTNode
{
    char data;
    BiTNode *left_next,*right_next;
}BiTNode,*BiTree;
typedef struct Queue
{
   BiTNode *Data[MAX_Queue_SIZE];
   int front,rear;
}Queue;
void InitQueue(Queue &Q)
{
    Q.rear=Q.front=0;
}
bool EmptyQueue(Queue Q)
{
    if(Q.rear==Q.front)
        return true;
    else return false;
}
void EnterQueue(Queue &Q,BiTNode *p)//入队
{
    if((Q.rear+1)%MAX_Queue_SIZE==Q.front)
        return ;
    else
    {
        Q.Data[Q.rear]=p;
        Q.rear=(Q.rear+1)%MAX_Queue_SIZE;
    }
}
void DeQueue(Queue &Q,BiTNode *p)//出对
{
    if(Q.rear==Q.front)
         return ;
    else
    {
        p=Q.Data[Q.front];
        Q.front=(Q.front+1)%MAX_Queue_SIZE;
    }
}
void Create_Tree(BiTree &T)//建立二叉树
{
    char ch;
    cin>>ch;
    if(ch=='#')
        T=NULL;
    else
    {
        T=(BiTree)malloc(sizeof(BiTNode));
        T->data=ch;
        Create_Tree(T->left_next);
        Create_Tree(T->right_next);
    }
}
void Visit(char ch)
{
    cout<<ch<<" ";
}
void Level_Order_Tree(BiTree T,Queue &Q)//层次遍历
{
    BiTNode *p;
    p=T;
    EnterQueue(Q,p);
    while(!EmptyQueue(Q))
    {
        DeQueue(Q,p);
        Visit(p->data);
        if(p->left_next)
        {
            EnterQueue(Q,p->left_next);
        }
        if(p->right_next)
        {
            EnterQueue(Q,p->right_next);
        }
    }
}
int main()
{
    BiTree T;
    Create_Tree(T);
    Queue Q;
    InitQueue(Q);
    cout<<"层次遍历:";
    Level_Order_Tree(T,Q);
    cout<<endl;
    return 0;
}
搜索更多相关主题的帖子: include return 二叉树 false 
2014-08-06 21:31
快速回复:【求助】帮我看看这段二叉树层次遍历代码哪里出错了
数据加载中...
 
   



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

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