已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
软件技术基础实验指导书实验三 排序二叉树的建立和查找一、实验题目:排序二叉树的建立和查找二、实验目的:掌握非线性数据结构的描述方法三、实验内容:(1)附录中是用链式结构实现二叉树的建立、查询和打印的源程序。请将他们输入计算机,编译、连接并运行。(2)读懂上述程序,并编写删除一个结点的子函数。四、实验报告要求: 软件技术基础实验报告实验名称:排序二叉树的建立和查找班级: 学号: 姓名:实验目的:掌握非线性数据结构的描述方法实验内容:(1)附录中是用链式结构实现二叉树的建立、查询和打印的源程序。请将他们输入计算机,编译、连接并运行。(2)读懂上述程序,并编写删除一个结点的子函数。实验原理:写出删除排序二叉树中一个结点的算法(形式语言)。实验步骤:写出调试、查找程序中问题的思路和步骤。实验结果:写出删除排序二叉树中一个结点的子程序。附录:二叉树的建立、查询、打印和遍历的源程序:#include#include/*/define the structure of an element of a tree/*struct tree char info; struct tree *left,*right; ;/*/explanation the functions /*struct tree *create_btree(struct tree *root,struct tree *r,char info);struct tree *search_btree(struct tree *root,char key);void print_btree(struct tree *r,int l);void PreOrder(struct tree *T); /先序递归遍历二叉树void InOrder(struct tree *T); /中序递归遍历二叉树void PostOrder(struct tree *T); /*/ the main function /*void main() char s100, c ; struct tree *root=0, *p; printf(Input a letter for Creating the Binary_Tree ( Directly press to stop ):n); do printf(Input a letter: ); gets(s);if (!root)root=create_btree(root,root,*s);elsecreate_btree(root,root,*s); while (*s) ;while ( c!=!)print_btree(root,0);printf(Enter a character to find( ! to stop ):);scanf(%s,&c);printf(n);p=search_btree(root,c); printf(n);printf(n先序遍历结果:); PreOrder(root); /先序递归遍历二叉树 printf(n中序遍历结果:); InOrder(root); printf(n后序遍历结果:); /中序递归遍历二叉树 PostOrder(root); printf(n); /* Btree.C 结束 */ struct tree *create_btree(struct tree *root,struct tree *r,char info) if (r =0 ) r=new (struct tree);if ( r = 0) printf(Out of memoryn); return 0 ; r-left= 0; r-right=0; r-info=info;if (root) if(infoinfo) root - left=r;else root-right=r;else r-right=0; r-left = 0; return r; if (info info)create_btree(r,r-left,info);if(info=r-info)create_btree(r,r-right,info); /* create_btree(root,r,info) */*/tree *search_btree(struct tree *root,char key)/*struct tree *search_btree(struct tree *p,char key) struct tree *root;root=p;if (!root) printf(Empty btreen); return root; while(root-info!=key) if(keyinfo) root=root-left;elseroot=root-right;if(root=0) printf(Search Failuren); return 0; /* while(root-info!=key) */if (root !=0)printf(Successful searchn key=%cn,root-info);return root ; /* *search_btree(root,key) */*/ print_btree /*void print_btree(struct tree *r,int l) int i;if (r = 0) return ;print_btree(r-left,l+1);for(i=0;iinfo);print_btree(r-right,l+1); void PreOrder(struct tree *T) if(T) printf(%c,T-info); /访问结点 PreOrder(T-left); /遍历左子树 PreOrder(T-right); /遍历右子树 void InOrder(struct tree *T)if(T) InOrder(T-left); /遍历左子树 printf(%c,T-info); /访问结点 InOrder
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025山东银座·英才幼儿园职业经理人招聘2人笔试历年常考点试题专练附带答案详解试卷3套
- 智能热计量与远程抄表方案
- 轨道交通延伸段工程环境影响报告书
- 供暖系统容量评估方案
- 2025东方电气(德阳)电动机技术有限责任公司社会招聘1人笔试历年典型考点题库附带答案详解试卷3套
- 德令哈公务员考试考场试题及答案
- 大专护理类公务员考试试题及答案
- 大兴公务员考试复审试题及答案
- 2025年及未来5年市场数据中国医药包装材料市场深度调查评估及投资方向研究报告
- 施工现场人员管理与培训方案
- 成人失禁相关性皮炎的预防与护理(2024年中华护理学会团体标准)
- 合江晚熟荔枝管理办法
- 国家电网反违章教育培训
- 安全生产责任制考核记录表
- 2025年中国电信招聘笔试参考题库附带答案详解
- 动物手术麻醉培训课件
- 业主信息保密管理制度
- 文化馆安全管理制度
- 常见止疼药讲课件
- JG/T 255-2020内置遮阳中空玻璃制品
- 加油站动火管理制度
评论
0/150
提交评论