




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
武汉纺织大学数据结构实验报告班级: 信管 专业 班 姓名: 学号: 实验时间: 2016 年 5 月 6 日 指导教师: 宋泽源 实验七:线性查找操作与应用一、实验目的: 1、掌握顺序查找、折半查找的基本方法和操作过程 2、掌握二叉排序树的基本方法和操作过程3、掌握查找效率的分析方法二、实验内容:1、编写程序,实现顺序查找操作,可参考书本p260/p25示例程序。 实验步骤: 、在java语言编辑环境中新建程序,建立一个顺序表(表长10),依次输入10个数据元素(对元素存放的先后顺序没有要求),并按照存储顺序输出所有元素; 、输入待查找关键字,在顺序表中进行顺序查找; 、输出查找结果。2、编写程序,实现有序表折半查找操作,可参考书本p263/p218示例程序。 实验步骤: 、在java语言编辑环境中新建程序,建立一个顺序表(表长10),依次输入10个数据元素(要求所有元素按照递增顺序排列),并按照存储顺序输出所有元素; 、输入待查找关键字,在有序表中进行折半查找; 、输出查找结果。3、编写程序,实现二叉排序树查找操作,可参考书本p277/p235示例程序。 实验步骤: 在java语言编辑环境中新建程序,依次输入10个数据元素,建立一个二叉排序树,并按照中序遍历输出所有元素;、输入待查找关键字,在二叉排序树中进行查找; 、输出查找结果。三、操作步骤:实验1:package search;import java.util.scanner;public class sequence public static void main(string args) throws java.io.ioexceptionseqlist list = new seqlist(10);int value=sequence.readint();for(int i=0;ivalue.length;i+)list.append(valuei);system.out.println(list.tostring();system.out.println(输入要查找的数:);scanner scan = new scanner(system.in);while(true)int key = scan.nextint();system.out.println(list.search(key)+在数组中下标为+list.indexof(key)+的位置);public static int readint() throws java.io.ioexceptionsystem.out.println(输入10个数:);byte buffer=new byte512;int count =system.in.read(buffer);if(count2)return null;string s=new string(buffer,0,count-2);string str=s.split( );int value=new intstr.length;int i=0,j=0;while(istr.length)tryvaluej=integer.parseint(stri);j+;catch(numberformatexception e)system.out.println(stri+不能转换为数组);finallyi+; if(i=j) return value; int keys=new intj; system.arraycopy(value, 0, keys, 0, j); return keys; 实验二package search;import java.util.scanner;public class binarysearch public static void main(string args)throws java.io.ioexceptionseqlist list = new seqlist(10);int value=binarysearch.readint();for(int i=0;ivalue.length;i+)list.append(valuei);system.out.println(list.tostring();system.out.println(使用折半查找方法,输入要查找的数:);scanner scan = new scanner(system.in);while(true)int key = scan.nextint();system.out.println(key+在数组中的下标为+list.binarysearch(value, key);public static int readint() throws java.io.ioexceptionsystem.out.println(输入10个升序数:);byte buffer=new byte512;int count =system.in.read(buffer);if(count2)return null;string s=new string(buffer,0,count-2);string str=s.split( );int value=new intstr.length;int i=0,j=0;while(imax)return -1;elseint mid=(max+min)/2;if(valuemid=key)return mid;else if(valuemidkey)return binarysearch(value,key,mid+1,max);elsereturn binarysearch(value,key,min,mid-1);实验三package search;import java.util.scanner;public class binarysorttree_ex public static void main(string args) throws java.io.ioexceptionbinarysorttree bstree=new binarysorttree();int values=binarysorttree_ex.readint();for(int i=0;ivalues.length;i+)bstree.insert(new integer(valuesi); /插入排序二叉树bstree.inorder(); /中根次序遍历二叉树/system.out.println(中序遍历输出二叉排序树+bstree.tostring();system.out.println(输入查找的数字:);scanner scan = new scanner(system.in);while(true)int key = scan.nextint();system.out.println(查找+key+,+(bstree.search(key)!=null?:不)+成功);public static int readint() throws java.io.ioexceptionsystem.out.println(输入10个数:);byte buffer=new byte512;int count =system.in.read(buffer);if(count2)return null;string s=new string(buffer,0,count-2);string str=s.split( );int value=new intstr.length;int i=0,j=0;while(istr.length)tryvaluej=integer.parseint(stri);j+;catch(numberfor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年【R1快开门式压力容器操作】考试题库及答案
- 2025年公路水运工程试验检测师公共基础试题库及答案(法规与技术标准)
- 2025年监理工程师之交通工程目标控制考试题库含答案a卷
- 桥梁招标课件
- 2025年品牌营销经理招聘面试模拟题与技巧解析
- 2026届安徽省亳州市第三十二中学高三化学第一学期期中联考模拟试题含解析
- 2025年电商运营岗位笔试模拟题及答案解析
- 2025护士资格证考试题库及答案
- 2025年大数据与人工智能课程考试试题及答案
- 2025年旅游管理与规划项目的考试试题及答案
- 小升初测试(试题)-2023-2024学年六年级下册数学苏教版
- 青少年抑郁症的预防和干预策略
- 考公行测言语理解与表达题库之选词填空公考公务员考试省考国考310题(含答案)
- 2021年度计算机审计初级网络培训测试题
- 康复科康复评定表
- 输液反应-完整版
- 【高质量】如何进行有效的校本研修PPT文档
- 水泥生产企业生产安全事故综合应急预案
- 食堂安全培训-课件
- 胆总管结石伴急性胆管炎
- 制度编写书写规范
评论
0/150
提交评论