欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOC文档下载  

    软件技术基础 查找和搜索 上机报告.doc

    • 资源ID:10287009       资源大小:22KB        全文页数:5页
    • 资源格式: DOC        下载积分:2
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要2
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    软件技术基础 查找和搜索 上机报告.doc

    第五次上机报告姓名:阚姗蕾 学号:2010012030037ex5_1:查找一、程序流程说明 设有序序列的数据元素为:(3,10,13,17,40,43,50,70)1)编写顺序查找函数2)编写二分查找函数3)在主程序中输入关键字(43和5),分别调用两种查找函数,输出结果。二、程序代码#include<stdio.h>#include<string.h>/顺序查找int seq_search(int a,int k,int n) int i = 0; while(ai!= k)i+; if(i<n) 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(amid<k) low = mid+1; else high = mid - 1; printf("searching failed"); return(-1);int main() int k,l; int a10= 3,10,13,17,40,43,50,70; printf("Please enter the key.n"); scanf("%d",&k); if(l = seq_search(a,k,8)>0) 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<stdio.h>#include<string.h>/简单选择法void select_sort(int table,int n) int h=0,j,min,temp; while(h<n) j=h; min=j; while(j<n) if(tablej<tablemin) min=j; j+; temp = tableh; tableh = tablemin; tablemin = temp; h+; /直接插入法void insert_sort(int table,int n) int tag=1,temp,j; while(tag<n) temp = tabletag; j = tag - 1; while( j > -1) if(temp < tablej) tablej+1=tablej; else tablej+1 = temp; break; j-; if(j<0)table0 = temp; tag+; /冒泡排序void bubble_sort(int table,int n) int i,j,t; for(i=0; i<n-1 ; i+) for(j = i; j < n-1; j+) if( tablej > 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; i<10; i+)scanf("%d",&tablei); printf("After select sort:n"); select_sort(table,10); for(i=0; i<10; i+) printf("%d ",tablei); printf("n"); printf("Please input the table:n"); for(i=0; i<10; i+) scanf("%d",&tablei); printf("After insert sort:n"); insert_sort(table,10); for(i=0; i<10; i+) printf("%d ",tablei); printf("n"); printf("Please input the table:n"); for(i=0; i<10; i+)scanf("%d",&tablei); printf("After bubble sort:n"); bubble_sort(table,10); for(i=0; i<10; 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 sort:87 61 170 275 462 512 513 653 897 908请按任意键继续. . .总结有了前几次写上机题的经验,这次上机时比较顺利的。个人感觉在这次上机中对于C语言的要求较低(或者是因为我没有选择比较复杂的数据结构),而对于算法的透彻理解非常重要。

    注意事项

    本文(软件技术基础 查找和搜索 上机报告.doc)为本站会员(土8路)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开