编写递归算法,计算二叉树中叶子结点的数目
来源:互联网 发布:芒果tv网络电视直播 编辑:程序博客网 时间:2024/04/20 08:00
#include<stdio.h>
struct BiTree{
char data;
struct BiTree *lchild;
struct BiTree *rchild;
};
struct BiTree* CreatBiTree(){
char x;
struct BiTree* p;
scanf("%c",&x);
if(x!='.'){
p=(struct BiTree*)malloc(sizeof(struct BiTree));
p->data=x;
p->lchild=CreatBiTree();
p->rchild=CreatBiTree();
}
else
p=NULL;
return p;
}
int LeafNum(struct BiTree *T){
if(!T)
return 0;
else
if(!T->lchild&&!T->rchild)
return 1;
else
return LeafNum(T->lchild)+LeafNum(T->rchild);
}
int main(){
int num;
struct BiTree* T;
printf("Please input the tree(pre):\n");
T=CreatBiTree();
while(T==NULL){
printf("empoty,again:\n");
T=CreatBiTree();
}
num=LeafNum(T);
printf("\nthe sum of leaf is:%d\n",num);
getch();
}
- 编写递归算法,计算二叉树中叶子结点的数目
- 以二叉链表为存储结构, 试编写计算二叉树中叶子结点数目的递归算法.
- 计算二叉树中叶子结点的数目
- 计算二叉树中叶子结点数的算法
- 编写递归算法 计算二叉树中叶子节点的个数
- 计算二叉树中叶子节点的数目
- {数据结构}计算二叉树中叶子结点个数
- 8-31 编写函数求二叉树中叶子结点的个数
- 统计二叉树中叶子节点的数目
- 求二叉树中叶子结点的个数
- 求二叉树中叶子结点的个数
- 输出二叉树中叶子结点的个数
- 如何计算树中叶子结点的个数?
- 二叉树中叶子节点的个数(递归)
- 二叉树中叶子节点的个数(非递归)
- 求二叉树中叶子数的算法
- 二叉树的先序中序后序以及递归算法求高度和结点数目
- 二叉树中叶子节点的个数
- uva 113 Power of Cryptography
- utf gb 等区别
- 说不尽的string字符串
- static 类成员
- Oracle:启动 Database Control 时出错
- 编写递归算法,计算二叉树中叶子结点的数目
- Visual C++通过ADO连接 SQL SERVER 2008
- 分析ms11-80 poc某些细节
- css属性~(积少成多)
- eclipse自动补全设置
- oracle 10g中dbms_mview.refresh()函数
- Rete算法笔记
- rman catalog库升级
- Win7下VMware虚拟机centos不能上网解决方案