软件技术基础 查找和搜索 上机报告.doc
《软件技术基础 查找和搜索 上机报告.doc》由会员分享,可在线阅读,更多相关《软件技术基础 查找和搜索 上机报告.doc(5页珍藏版)》请在三一办公上搜索。
1、第五次上机报告姓名:阚姗蕾 学号:2010012030037ex5_1:查找一、程序流程说明 设有序序列的数据元素为:(3,10,13,17,40,43,50,70)1)编写顺序查找函数2)编写二分查找函数3)在主程序中输入关键字(43和5),分别调用两种查找函数,输出结果。二、程序代码#include#include/顺序查找int seq_search(int a,int k,int n) int i = 0; while(ai!= k)i+; if(in) printf(searching sucdess); return(i); else printf(searching failed
2、); return(-1); /二分查找int bin_search(int a,int k,int n) int low,high,mid; low = 0; high = n-1; while(low = high) mid = (low + high) / 2; if(amid = k) printf(searching sucdess); return(mid); else if(amid0) printf(nThe location of the key is %dn,l); printf(Please enter the key.n); scanf(%d,&k); if(l = b
3、in_search(a,k,8)0) printf(nThe location of the key is %dn,l);三、上机时遇到的问题1)错误现象:E:ACMcs.cpp(4) : error C2065: a : undeclared identifier原因:函数中数组没有定义解决办法:在形参前面补充数据类型int2)现象:输入关键字后意外关闭原因:顺序查找是i没有进行初始化解决办法:初始化i=0四、输入与输出Please enter the key.43searching sucdessThe location of the key is 1Please enter the ke
4、y.5searching failedProcess returned 0 (0x0) execution time : 12.517 sPress any key to continue.ex5_2:排序一、程序流程说明1)编写简单选择法函数2)编写直接插入法函数3)编写冒泡法排序函数4)在主程序中输入一组数据元素(513,87,512,61,908,170,897,275,653,462),分别调用三种排序函数,输出每趟排序结果。 二、程序代码#include#include/简单选择法void select_sort(int table,int n) int h=0,j,min,temp
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 软件技术基础 查找和搜索 上机报告 软件技术 基础 查找 搜索 上机 报告
链接地址:https://www.31ppt.com/p-2394744.html