下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/*/*实验二排序二叉树的建立、查找、遍历、结点删除*/*/#include#include#includestruct tree char info; struct tree *left,*right; ;struct tree *create_btree(struct tree *root,struct tree *r,char info);struct tree *search_btree(struct tree *root,char key);struct tree *delete_node(struct tree *root,char key);void print_btree(st
2、ruct tree *r,int l);void preorder(struct tree *t); /先序递归遍历二叉树void inorder(struct tree *t); /中序递归遍历二叉树void postorder(struct tree *t); void main() char s100, c, e; struct tree *root=0, *p; printf(input a letter for creating the binary_tree ( directly press to stop ):n); do printf(ninput a letter: ); e
3、=_getch();_putch(e);if(e=13) break;if (!root)root=create_btree(root,root,e);elsecreate_btree(root,root,e);/gets(s);/if(s0=0) break;/if (!root)/root=create_btree(root,root,*s);/else/create_btree(root,root,*s); while (*s) ;printf(n先序遍历结果:);preorder(root); /先序递归遍历二叉树printf(n中序遍历结果:);inorder(root); prin
4、tf(n后序遍历结果:); /中序递归遍历二叉树postorder(root); printf(n);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);c=1;while ( c!=!) /删除节点print_btree(root,0);printf(enter a character to delete( ! to stop ):);scanf(%s,&c);p
5、rintf(n);root=delete_node(root,c); /删除结点后返回树的根 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 r
6、oot-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);return root; /* create_btree(root,r,info) */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(t-right); /遍历右子树 void postorder(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年广东省湛江市地理生物会考考试题库(附含答案)
- 2025年四川省自贡市八年级地生会考真题试卷+答案
- 医患关系沟通的核心要素
- 护理病例书写标准与临床实践结合
- 2026商业秘密保护合作协议模板
- 2026年房屋租赁合同纠纷处理办法
- 2026物资采购自查报告(2篇)
- 物业公司年流动人口计划生育工作计划(2篇)
- 妊娠剧吐的并发症预防与处理
- 压疮的预防措施与执行要点
- 776-2015托幼机构消毒卫生规范
- 电离辐射危害及预防方法
- 系统解剖学课件:内脏神经
- GB/T 19515-2023道路车辆可再利用率和可回收利用率要求及计算方法
- GB/T 15587-2023能源管理体系分阶段实施指南
- ICD-9-CM3编码与手术分级目录
- 数据库原理及应用-课件
- 探究物联网的技术特征-说课
- GB/T 18804-2022运输工具类型代码
- LY/T 1726-2008自然保护区有效管理评价技术规范
- GA/T 951-2011紫外观察照相系统数码拍照规则
评论
0/150
提交评论