二叉树的遍历以及叶子节点个数的计算(The calculation of two binary tree traversal and the number of leaf nodes.).docVIP
- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
二叉树的遍历以及叶子节点个数的计算(The calculation of two binary tree traversal and the number of leaf nodes.)
二叉树的遍历以及叶子节点个数的计算(The calculation of two binary tree traversal 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 = = 0) (t - rchild = = null)) num = 1;
else
{
num1 = countleaf (t - lchild);
countleaf num2 = (t - rchild);
num = num1 + num2;
}
return num;
}
/ / 先序遍历二叉树
void preorder (bitree * t)
{
if (t! = = null)
{
printf (% 2, t - data);
preorder (t - lchild);
preorder (t - rchild);
}
}
/ / 中序遍历二叉树
void inorder (bitree * t)
{
struct bitnode * p;
struct stack bitnode * [20];
int top = 0;
p = t;
while (p | | top! = 0)
{
while (p)
{
stack (top + +] = p;
p = p lchild;
}
p = stack [top];
printf (%
您可能关注的文档
- 三点共面问题(Three point coplanar problem).doc
- 三相电容自动补偿(Automatic compensation capacitor).doc
- 三相逆变器中igbt的几种驱动电路的分析(Analysis of the driving circuit of the three-phase inverter of several IGBT).doc
- 三级营养师考试辅导膳食纤维(Three nutritionists test counseling dietary fiber).doc
- 三维产品信息(Three dimensional information products).doc
- 三维程序游戏制作基本常识01(01 basic knowledge of 3D game program).doc
- 三维坐标系和几何学(The 3D coordinates and geometry).doc
- 三行情书全集(Three market works).doc
- 三角梅的养护(Bougainvillea maintenance).doc
- 三角高程(Gao Cheng triangle).doc
- 二叉树的建立与遍历,叶子结点的数目以及树的深度的求法,采用递归求解(With the establishment of binary tree traversal two, method for the number of leaf nodes and the depth of the tree, the recursive solution).doc
- 二极管2(2 diode).doc
- 二次脉冲法查寻电缆故障在宝钢的应用(Two pulse search method of cable fault in Baosteel).doc
- 二次函数应用题(Quadratic function application problems).doc
- 二氧化氯的介绍(The introduction of chlorine dioxide).doc
- 二氧化硅比表面积测试(The specific surface area of silica test).doc
- 二氧化碳保护焊接规范和操作工艺作业指导书(Carbon dioxide arc welding specification and process work instructions).doc
- 二氧化碳气驱强化采油(co2-eor)的原理(Carbon dioxide gas flooding enhanced oil recovery (co2-eor) principle).doc
- 二甲双弧(Two armor double arc).doc
- 二灰碎石路面基层施工(Two ash macadam base construction).doc
文档评论(0)