| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 701 人关注过本帖
标题:有关二叉树的小问题
只看楼主 加入收藏
MyStar
Rank: 1
等 级:新手上路
帖 子:75
专家分:9
注 册:2010-3-30
结帖率:93.75%
收藏
已结贴  问题点数:20 回复次数:3 
有关二叉树的小问题
#include <iostream>
using namespace std;
struct BiNode
{
char data;
BiNode *lchild ,*rchild;
};
BiNode *Creat()
{
    char ch;BiNode *root;
   
cin>>ch;
if(ch=='#') root=NULL;//建立一颗空树
else{
        root=new BiNode;
        root->data=ch;
        //cout<<root->data;
        root->lchild=Creat();//递归建立左子树
        root->rchild=Creat();//递归建立右子树
    }
return 0;
}

void output(BiNode *root)
{
    if(root!=NULL)
     cout<<root->data<<endl;
     output(root->lchild);
     output(root->rchild);
   
}
int main()
{
    BiNode *a;
    Creat();
    output(a);
    return 0;
}
程序不知怎么没输出结果!!!请大家指点一下!!谢谢

搜索更多相关主题的帖子: 二叉树 
2010-05-22 16:59
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:20 
#include <iostream>
using namespace std;

struct BiNode
{
char data;
struct BiNode *lchild ,*rchild;
};
BiNode *Creat()
{
    char ch;
    BiNode *root;
   
    cin>>ch;
    if(ch=='#')
        root=NULL;//建立一颗空树
    else
    {
        root=new BiNode;
        root->data=ch;
        //cout<<root->data;
        root->lchild=Creat();//递归建立左子树
        root->rchild=Creat();//递归建立右子树
    }
    return root;
}

void output(BiNode *root)
{
    if(root!=NULL)
    {
         cout<<root->data;
         output(root->lchild);
         output(root->rchild);
    }
   
}
int main()
{
    BiNode *a;
    a=Creat();
    output(a);
    cout<<endl;
    return 0;
}
图片附件: 游客没有浏览图片的权限,请 登录注册
2010-05-22 17:50
xichong
Rank: 7Rank: 7Rank: 7
来 自:四川南充
等 级:黑侠
威 望:2
帖 子:146
专家分:582
注 册:2009-6-10
收藏
得分:0 
建立一棵二叉树就要返回它的根节点指针,表明这种数据类型被一个变量保存起来了,以后才可以继续使用。
2010-05-22 18:20
MyStar
Rank: 1
等 级:新手上路
帖 子:75
专家分:9
注 册:2010-3-30
收藏
得分:0 
谢谢啦!!
2010-05-22 20:03
快速回复:有关二叉树的小问题
数据加载中...
 
   



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

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