gjq实验3-排序二叉树的建立和查找

上传人:F****n 文档编号:97823482 上传时间:2019-09-06 格式:DOC 页数:7 大小:24.50KB
返回 下载 相关 举报
gjq实验3-排序二叉树的建立和查找_第1页
第1页 / 共7页
gjq实验3-排序二叉树的建立和查找_第2页
第2页 / 共7页
gjq实验3-排序二叉树的建立和查找_第3页
第3页 / 共7页
gjq实验3-排序二叉树的建立和查找_第4页
第4页 / 共7页
gjq实验3-排序二叉树的建立和查找_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《gjq实验3-排序二叉树的建立和查找》由会员分享,可在线阅读,更多相关《gjq实验3-排序二叉树的建立和查找(7页珍藏版)》请在金锄头文库上搜索。

1、软件技术基础实验指导书实验三 排序二叉树的建立和查找一、实验题目:排序二叉树的建立和查找二、实验目的:掌握非线性数据结构的描述方法三、实验内容:(1)附录中是用链式结构实现二叉树的建立、查询和打印的源程序。请将他们输入计算机,编译、连接并运行。(2)读懂上述程序,并编写删除一个结点的子函数。四、实验报告要求: 软件技术基础实验报告实验名称:排序二叉树的建立和查找班级: 学号: 姓名:实验目的:掌握非线性数据结构的描述方法实验内容:(1)附录中是用链式结构实现二叉树的建立、查询和打印的源程序。请将他们输入计算机,编译、连接并运行。(2)读懂上述程序,并编写删除一个结点的子函数。实验原理:写出删除

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

3、 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(Inpu

4、t 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=

5、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) pri

6、ntf(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(st

7、ruct 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

8、!=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); /访问结点 P

9、reOrder(T-left); /遍历左子树 PreOrder(T-right); /遍历右子树 void InOrder(struct tree *T)if(T) InOrder(T-left); /遍历左子树 printf(%c,T-info); /访问结点 InOrder(T-right); /遍历右子树 void PostOrder(struct tree *T) if(T) PostOrder(T-left); /遍历左子树 PostOrder(T-right); /访问结点 printf(%c,T-info); /遍历右子树 在能力与知识结构方面,要求学生应具有扎实的专业和日语语言基础,熟练掌握日语听、说、读、写、译的基本技能;了解日本社会及日本文化等方面的基本知识,熟悉日本国情,具有一定的日本人文知识及运用这些知识与日本人进行交流的能力。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号