网站大量收购独家精品文档,联系QQ:2885784924

二叉树的应用实验报告.doc

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
二叉树的应用实验报告

实验三 课程名称 班级:嵌入式2班 完成日期: 姓名: 学号: 指导教师: 实验名称: 实验序号: 实验成绩: 一、实验目的及要求 二、实验环境、实验内容 求出它的高度; 用嵌套形式输出。 四、调试过程及实验结果 五、总结 六、附录(源程序清单)#include stdio.h #include stdlib.h #include malloc.h #define NULL 0 typedef int telemtype; typedef int status; typedef struct bitnode{ char data; struct bitnode *lchild,*rchild; }bitnode,*bitree; void create(bitree T){ char ch; ch=getchar( ); if(ch==#) T=NULL; else{ T=(bitree)malloc(sizeof(bitnode)); T-data=ch; create(T-lchild); create(T-rchild); } } void preorder(bitree T) { if (T) {printf (%c,T-data); preorder(T-lchild); preorder(T-rchild); } } void inorder(bitree T) {if (T) {inorder(T-lchild); printf (%c,T-data); inorder(T-rchild); } } void postorder(bitree T) { if (T) { postorder(T-lchild); postorder(T-rchild); printf(%c,T-data); } } void countleaf(bitree T,intn) { if (T) { countleaf(T-lchild,n); if(!T-lchild !T-rchild) n++; countleaf(T-rchild,n); } } void depth(bitree T,int dep) { int dep1,dep2; if(!T) dep=0; else {depth(T-lchild,dep1); depth(T-rchild,dep2); dep=dep1dep2?dep1+1:dep2+1; } } void output(bitree T) {if(T) {printf(%c,T-data); if(T-lchild||T-rchild) {printf((); output(T-lchild); if(T-rchild) printf(,); output(T-rchild); printf()); } } } int main( ) { bitree T; int n=0,dep; printf(请输入二叉树先序列:); create (T); printf(\n); printf(先序为:); preorder(T); printf(\n); printf(中序为:); inorder(T); printf(后序为:); postorder(T); printf(\n); depth(T,dep); printf(深度dep=%d\n,dep); countleaf(T,n); printf(叶子结点数n=%d\n,n); printf(二叉树的嵌套括号形式为:); output(T); printf(\n); return 0; } 1

文档评论(0)

xy88118 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档