- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
二叉树的遍历以及叶子节点个数的计算(Two traversal of the tree and the number of leaf nodes)
二叉树的遍历以及叶子节点个数的计算(Two traversal of the tree and the number of leaf nodes)
# includes stdio.h
# includes stdlib.h
# includes string.h
# define null 0
# define true 1
# define false 0
# define okay 1
# define error 0
# define infeasible - 1
# define overflow - 2
typedef int status;
# define stackincrement 10
typedef int status;
typedef int telemtype;
typedef struct bitnode
{
char date;
struct bitnode * lchild;
struct bitnode * rchild;
} bitree;
/ / ----------------------------------- 创建二叉树
bitree * createbitree (bitree * t)
{
char ch;
if ((ch = getchar () = = #) t = null;
else
{
t = (bitree *) malloc (sizeof (bitnode));
t - date = ch;
t - lchild = createbitree (t - lchild);
t - rchild = createbitree (t - rchild);
}
return t;
}
/ / ------------------------------ 查找结点
/ * status searchbitree (bitree * t, telemtype x)
{
bitree * bt;
if (t! = = null)
{
if (bt - date = = x)
printf (你查找的结点存在该二叉树中);
return ok;
searchbitree (t - lchild, x);
searchbitree (t - rchild, x);
}
else
printf (% d不在该树中 , x).
return null;
}
* /
/ / ------------------------------ 求深度
status depthbitree (bitree * t)
{
int depthval, depthleft, depthright;
if (! t) depthval = 0;
else
{
depthleft = depthbitree (t - lchild);
depthright = depthbitree (t - rchild);
depthval = 1 + (depthleft depthright? depthleft: depthright);
}
return depthval;
}
/ / ---------------------------- 计算叶子结点数
status countleaf (bitree * t)
{
int num1;
int num2;
int num;
if (t = = null) num = 0;
else
if ((t - lchild = = null) (t - rchild = = null)) n = 1;
else
{
num1 = countleaf (t - lchild);
num2 = countleaf (t - rchild);
num = num1 + num2;
}
return num;
}
/ / 先序遍历二叉树
void preorder (bitree * t)
{
if (t! = = null)
{
printf (% 2, t - date);
preorder (t - lchild);
preorder (t - rchild);
}
}
/ / 中序遍历二叉树
中序遍历(bitree * T)
{
struct Bitnode * P;
BiTNode *堆栈结构[ 20 ];
int = 0;
P = T;
而(P | |顶!= 0)
{
而(P)
{
栈[顶+ +] = P;
P = P - 左右;
}
P =栈[顶]—;
printf(“%c”,P>数据);
P = P - rchild;
}
}
/ /后序遍历二叉树
无效的后序(二叉树* T)
{
如果(T!= null)
{
您可能关注的文档
- 三国志英杰传 极限等级(Legend of the Three Kingdoms).doc
- 三国战神答题答案2014.10.01(Three ares answer questions 2014.10.01).doc
- 三国战役(Battle of the Three Kingdoms).doc
- 三国志英杰传全攻略(Legend of the Three Kingdoms).doc
- 三国战纪1代117版本诸葛亮快速通关攻略(Knights of Valor 1 generation version 117 Zhu Geliang wii).doc
- 三国战纪1代攻略(Knights of Valor 1 generation strategy).doc
- 三国战纪2_隐藏任务+出招表(Knights of Valor 2_ hidden task + moves the table).doc
- 三国战纪2代(群雄争霸)出招表(Knights of Valor 2 generation (II) moves the table).doc
- 三国战记攻略(Three wars Raiders).doc
- 三国所有人物(部分人物的字)(All characters in the Three Kingdoms (characters of some characters)).doc
- 二千多道菜的做法(The more than 2000 dish).doc
- 二年19班对联集锦(Two year 19 class couplets).doc
- 二年级下册5单元复习资料(Review of the second grade II unit 5).doc
- 二年级下册6单元复习资料(Review of the second grade II unit 6).doc
- 二年级个性化作文教学(Individualized composition teaching in grade two).doc
- 二年级优秀作文赏析(Appreciation of outstanding compositions in grade two).doc
- 二年级数学下册 平移和旋转一课一练1 苏教版(The second grade mathematics book translation and rotation Practice Book 1 Jiangsu Edition).doc
- 二年级推荐读物(Recommended readings for grade two).doc
- 二年级数学下册_应用题练习2一课一练(无答案)_北京版(The second grade math book _ application exercises 2 lesson of a practice (no answer) _ Beijing Edition).doc
- 二年级数学应用题(Two grade math problem).doc
最近下载
- 商业秘密保护知识培训.ppt VIP
- 生态学全套配套课件第三版杨持第二章.ppt VIP
- 《向上管理 与你的领导相互成就》读书笔记思维导图.pptx VIP
- 钢结构工程维修施工方案.docx VIP
- 2023年武汉科技大学计算机科学与技术专业《计算机网络》科目期末试卷A(有答案).docx VIP
- 电信春节通信保障应急预案.docx VIP
- 女装设计 全套课件(上).pptx VIP
- 珠海市政府投资项目建设监督管理中心招考合同制职员考前自测高频考点模拟试题(共500题)含答案详解.docx VIP
- 体例格式9:工学一体化课程《小型网络安装与调试》任务4学习任务工作页.docx VIP
- 建筑节能工程监理质量评估报告.pdf VIP
文档评论(0)