c语言的中序二叉树程序
来源:互联网 发布:苹果手机报警软件 编辑:程序博客网 时间:2024/05/22 17:42
#include "stdio.h"
#include "string.h"
#define NULL 0
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree Create(BiTree T){
char ch;
ch=getchar();
if(ch=='#')
T=NULL;
else{
if(!(T=(BiTNode *)malloc(sizeof(BiTNode))))
printf("Error!");
T->data=ch;
T->lchild=Create(T->lchild);
T->rchild=Create(T->rchild);
}
return T;
}
void Preorder(BiTree T){
if(T){
printf("%c",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
}
}
int Sumleaf(BiTree T){
int sum=0,m,n;
if(T){
if((!T->lchild)&&(!T->rchild))
sum++;
m=Sumleaf(T->lchild);
sum+=m;
n=Sumleaf(T->rchild);
sum+=n;
}
return sum;
}
void zhongxu(BiTree T){
if(T){
zhongxu(T->lchild);
printf("%c",T->data);
zhongxu(T->rchild);
}
}
void houxu(BiTree T){
if(T){
houxu(T->lchild);
houxu(T->rchild);
printf("%c",T->data);
}
}
int Depth(BiTree T){
int dep=0,depl,depr;
if(!T) dep=0;
else{
depl=Depth(T->lchild);
depr=Depth(T->rchild);
dep=1+(depl>depr?depl:depr);
}
return dep;
}
main(){
BiTree T;
int sum,dep;
T=Create(T);
Preorder(T);
printf("/n");
zhongxu(T);
printf("/n");
houxu(T);
printf("/n");
sum=Sumleaf(T);
printf("%d",sum);
dep=Depth(T);
printf("/n%d",dep);
}
- c语言的中序二叉树程序
- C语言二叉树程序
- C语言:二叉树的中序遍历
- 一个关于二叉树的创建、先序遍历、中序遍历、后序遍历、求叶子节点的完整函数的c语言完整程序。
- 根据二叉树的前序遍历和中序遍历构建二叉树的c语言完整代码
- 【面试算法系列】已知二叉树的前序和中序遍历重建二叉树 - C语言实现
- 二叉树的先序,中序,后序遍历 c语言
- 数据结构 二叉树的递归算法、前序、中序、后序遍历(c语言实现)
- c语言实现二叉树的先序遍历,中序遍历,后序遍历
- 数据结构 二叉树的先序 中序 后序遍历(linux 下c语言实现)
- c语言原生实现二叉树的 非递归 中序 先序 后序 遍历
- c语言实现二叉树(BiNodeTree)的建立与先序遍历,中序遍历
- 二叉树的创建、前/中/后序遍历、按层遍历C语言实现
- (C语言)通过对二叉树的先序和中序遍历构建该二叉树,然后输出该二叉树的层序遍历结果
- c语言的二叉树的创建
- 平衡二叉树的构建 用函数回调来扩展程序 c语言实现
- c语言实现二叉树的遍历和创建程序(附带注释)
- C语言 二叉树
- 八个学习点帮助你全面认识Oracle数据库
- 项目管理的一些心得技巧
- 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度?
- WebApplicationContext : org.springframework.web.context.ContextLoaderListener作用
- VC 改变对话框背景(添加背景图片)
- c语言的中序二叉树程序
- ssis文件系统任务
- Tomcat6下配置数据源及使用
- My first blog
- 文件下载
- sequence與connect by的應用
- Android自由选择TextView的文字
- SQL2005 属性 IsLocked 不可用于 登录[sa]
- 关于KVM和Xen不得不说的事儿 (转帖)