



免费预览已结束,剩余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); 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 = bin_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 key.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; while(hn) j=h; min=j; while(jn) if(tablejtablemin) min=j; j+; temp = tableh; tableh = tablemin; tablemin = temp; h+; /直接插入法void insert_sort(int table,int n) int tag=1,temp,j; while(tag -1) if(temp tablej) tablej+1=tablej; else tablej+1 = temp; break; j-; if(j0)table0 = temp; tag+; /冒泡排序void bubble_sort(int table,int n) int i,j,t; for(i=0; in-1 ; i+) for(j = i; j tablej+1) t = tablej; tablej = tablej+1; tablej+1 = t; int main() int i; int table10= 0; printf(please input the table:n); for(i=0; i10; i+)scanf(%d,&tablei); printf(after select sort:n); select_sort(table,10); for(i=0; i10; i+) printf(%d ,tablei); printf(n); printf(please input the table:n); for(i=0; i10; i+) scanf(%d,&tablei); printf(after insert sort:n); insert_sort(table,10); for(i=0; i10; i+) printf(%d ,tablei); printf(n); printf(please input the table:n); for(i=0; i10; i+)scanf(%d,&tablei); printf(after bubble sort:n); bubble_sort(table,10); for(i=0; i10; i+)printf(%d ,tablei); printf(n);三、上机时遇到的问题现象:after bubble sort:513 513 513 513 908 908 908 908 908 908原因:tablei与tablej交换的时候三行语句顺序有误解决办法:调整语句顺序四、输入与输出please input the table:513 87 512 61 908 170 897 275 653 462after select sort:61 87 170 275 462 512 513 653 897 908please input the table:513 87 512 61 908 170 897 275 653 462after insert sort:61 87 170 275 462 512 513 653 897 908please input the table:513 87 512 61 908 170 897 275 653 462after bubble s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2025学年九年级历史下册 第二单元 凡尔赛-华盛顿体系下的世界 第3课 凡尔赛-华盛顿体系说课稿 新人教版
- 2025智能交通平台渠道代理合同
- 机械厂员工转正结果管理办法
- 2025杭州市房屋租赁合同范本
- 2025年农业种植合同范本B
- 《大堰河-我的保姆》《秦腔》教学设计 2023-2024学年统编版高中语文选择性必修下册
- 第3课 色彩斑斓水彩画教学设计-2023-2024学年小学信息技术(信息科技)五年级下册人教·内蒙古版
- HZL54河南电建汽车产业园土地租赁及建设合同
- 电力改造项目安全责任免除合同范本
- 海外电子商务合同跨境法律适用及风险防范策略
- 辽宁省沈阳市2024-2025学年八年级上学期期末考试英语试题(含答案无听力原文及音频)
- 小班晨间活动体能大循环
- 绿化小型工程合同范例
- 涂层材料与叶轮匹配性研究-洞察分析
- 讯问笔录课件教学课件
- 《建筑工程设计文件编制深度规定》(2022年版)
- 2.3地表形态与人类活动课件湘教版(2019)高中地理选择性必修一
- 病例报告表(CRF)模板
- 辽宁省名校联盟2024-2025学年高三上学期10月联考数学试卷
- 广东省珠海市香洲区文园中学2024-2025学年七年级上学期10月月考数学试卷(无答案)
- 2019年医疗器械体外诊断与病理诊断行业分析报告
评论
0/150
提交评论