版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、数据结构二分法查找实验班级:计算机应用技术10-1班 学号:10602101018姓名:石美远一、实验目的及要求:掌握有关二分法函数对数据的统计的基本操作和存储结构,并编写相应的基本操 作算法。二、实验内容:1、完成插入排序函数的程序2、用循环完成二分法查找函数3、用递归完成二分法查找函数4、在二分法函数中统计出查找次数与被查找关键字在有序表中的位置5、最好能与顺序查找对比查找效率三、实验准备:计算机设备;程序调试环境的准备,如VC6、C+或WIN-TC环境;实验内容的算法分析与代码设计准备。四、函数实现1、二分法函数#include#define MAXSIZE 10int BinSearc
2、h(int s,int low, int high, int key) int mid,count=0;while(lowsmid) low=mid+1;else high=mid-1;return -1;int BinSearch2(int s,int low, int high, int key) int mid;static int count=0;while(lowsmid) return BinSearch2(s,mid+1,high,key);elsereturn BinSearch2(s,low,mid-1,key);return -1;int main() int mMAXSI
3、ZE = 4,7,-1,0,8,12,20,3,2,15,i,length,key,location;for(length=1;length=0) if(keymi) mi+1=mi;i-;else break;mi+1=key;printf(nnSorted:);for(i=0;i10;i+)printf(%3d ”,mi);printf(nn);location=BinSearch(m,0,9,7);printf(nt location=%dn”,location);location=BinSearch2(m,0,9,12);printf(nt location=%dn”,location
4、);return 0;2、二分法函数统计数据#include#define MAXSIZE 10int BinSearch(int s,int low, int high, int key) int mid,count=0;while(lowsmid) low=mid+1;else high=mid-1;printf(nt Search fail!n);return -1;int BinSearch2(int s,int low, int high, int key) int mid;static int count=0;while(lowsmid) return BinSearch2(s,m
5、id+1,high,key);elsereturn BinSearch2(s,low,mid-1,key);printf(nt Search fail!n);return -1;void InserSort(int m,int length) int key,i,k;for (k=1;k=0) if(keymi) mi+1=mi;i-;else break;mi+1=key;int main() int mMAXSIZE = 4,7,-1,0,8,12,20,3,2,15,location,len=10,x,i;InserSort(m,len);printf(nnSorted:);for(i=
6、0;i10;i+)printf(%3d ”,mi);printf(nn Input the search data:);scanf(%d”,&x);location=BinSearch(m,0,len-1,x);printf(nt location=%dn,location);location=BinSearch2(m,0,len-1,x);printf(nt location=%dn,location);return 0;五、测试(在主函数中调用函数测试功能)#include#include#define MAXSIZE 80int main(void) char p1=,p2=;print
7、f(nt (1)p1-length=%d p2-length=%dn,StrLen(p1),StrLen(p2);Strcat(p1,p2);printf(nt (2)p1=%sn,p1);printf(nt (3)the result is %dn,Strcmp(p1,p2) );ReverseStr(pl);printf(nt (4)p1=%sn,p1);getch();return 0;实验截图:c: C:Documents and SettingsAdministrator桌面、二分法RDebug6.EKeSorted: -10234?8121520count=3location=6count=2location=8Press any key to continuec: C:Document5 and SettingsAdministrator桌面、二分法KDebugBinsearch.eKeaiSorted: -10234?8121520Input the search data:7count=3location=6count=3location=6Press any key to continue六、心得体会通过这次的实验,我又学到了有关二分法函数的调用的很多的知识,从这个函
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【核心素养】人音版二年级下册第1课《春之歌》教案
- 全国中图版高中信息技术选修1第一单元尝试软件开发第二节《项目实现》教学设计
- 北京市101中学2024-2025学年高三下期中教学情况调研化学试题含解析
- 人教版 七年级上册 音乐 第1单元 中学时代-飞来的花瓣 教案
- 人音版音乐三年级上册放牧 第一课时老水牛角弯弯(教案)
- 湘美 版一年级美术上册《16. 手拉手好朋友》教学设计
- 高一上学期体育与健康人教版 五步拳 教案
- 第三单元第1课 《诗书画印的完美结合》教案 人教版初中美术八年级上册
- 西南师大版八年级音乐下册第3单元《花儿与少年》教案
- 1合欢树 教案 高教版语文基础模块下册
- H13-111 HCIA鲲鹏应用开发题库(含答案)
- 《电子实习》教学大纲
- TYNAEPI 0001-2024 有机固废低温绝氧碳化处理工程技术规
- 第五课 和谐的师生关系(教学设计)
- 浙江杭州劳务派遣人员招考聘用(派遣至浙江大学信息技术中心)(高频重点复习提升训练)共500题附带答案详解
- 2024-2030年中国催化剂行业深度调研及投资前景预测研究报告
- 村积分制实施方案
- 2023年中考英语备考让步状语从句练习题(附答案)
- 安全隐患排查月度分析
- 天然气安全周知卡
- 【自考复习资料】00288社会调查方法(按章节整理)
评论
0/150
提交评论