| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 325 人关注过本帖
标题:二叉树的链式建立和返回叶子节点数,编译没问题但运行有问题??
只看楼主 加入收藏
czwx
Rank: 1
等 级:新手上路
帖 子:6
专家分:3
注 册:2015-10-4
结帖率:100%
收藏
 问题点数:0 回复次数:0 
二叉树的链式建立和返回叶子节点数,编译没问题但运行有问题??
程序代码:
#include<stdio.h>
#include<malloc.h>
struct BTnode
{
    char data;
    struct BTnode *Lchild,*Rchild;
};
void CreateBTree(struct BTnode *B)
{

 char ch=getchar();


 if(ch=='a')

 {
        B=NULL;

 }

 else

 {
         B=(struct BTnode *)malloc(sizeof(struct BTnode));

   B->data=ch;

   CreateBTree(B->Lchild);

         CreateBTree(B->Rchild);
}
}

 int Countleaf(struct BTnode *B)

 {
     if(B==NULL) return 0;
     if(B->Lchild==NULL&&B->Rchild==NULL) return 1;
     return(Countleaf(B->Lchild)+Countleaf(B->Rchild));

 }
void main()
{
    struct BTnode B;
CreateBTree(&B);
Countleaf(&B);
}
搜索更多相关主题的帖子: 二叉树 color 叶子 二叉树 color 叶子 
2015-11-01 11:09
快速回复:二叉树的链式建立和返回叶子节点数,编译没问题但运行有问题??
数据加载中...
 
   



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

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