下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/CNFIA 262-2026药食同源火锅调味料
- T/CMCHA 002-2023宫腔镜下子宫肌瘤去除术管理规范
- 江西省上饶市部分学校2027届高三上学期学情检测物理试卷(含答案)
- 2025-2026年电子商务师考试网络营销基础知识模拟试卷
- 安徽六安市叶集皖西当代中学2025-2026学年高一上学期期末检测试题(B卷)化学试题(含答案)
- 2025-2026年浙江省人教版初中化学九年级下册第5章综合测试题库
- 2025-2026年会计信息系统应用模拟试题
- 2026年吉林省民办中小学小升初数学联考真题试卷及答案
- 夏航空乘机上旅客强行开舱门处置模拟试卷及答案
- T/CI 681-2024快递运费计算方式规范
- 人教版五年级上册语文单元同步测试题(附答案)
- 江西财经大学《Java》2025-2026学年期末试卷
- 2025年老年人冬季防摔倒培训
- 科技小院建设协议书
- 机器人操作培训课件
- 西南交通大学2025年秋季公开招聘管理与其他专技人员调减招聘岗位笔试考试参考题库及答案解析
- 2025年国家电网招聘之管理类通关考试题库带答案解析
- 知道智慧树解密黄帝内经满分测试答案
- 2024年植物嫁接职业技能考试题库及答案
- CJ/T 256-2016分体先导式减压稳压阀
- 新药研究与开发技术 课件 第1-3章 概论、新药的发现研究、新药的工艺与质量研究
评论
0/150
提交评论