- 1、本文档共39页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
明明的随机数 /problem/1 #includestdio.h int a[1001]; int main() { int i,n,t,ans=0; scanf(%d,n); for(i=1;i=n;i++) { scanf(%d,t); if(a[t]==0){a[t]=1;ans++;} } printf(%d\n,ans); for(i=1;i=1000;i++) if(a[i]==1)printf(%d ,i); } #includestdio.h int partition(int *a,int low,int high) { int pivotkey; a[0]=a[low]; pivotkey=a[low]; while(lowhigh) { while(lowhigha[high]=pivotkey) high--; a[low]=a[high]; while(lowhigha[low]=pivotkey) low++; a[high]=a[low]; } a[low]=a[0]; return low; } void sort(int *a,int low,int high) { int pivotloc; if(lowhigh) { pivotloc=partition(a,low,high); sort(a,low,pivotloc-1); sort(a,pivotloc+1,high); } } void main() { int a[21]; int *p; int i; printf(input 20 numbers:); for(i=1;i21;i++) scanf(%d,a[i]); p=a; sort(p,1,20); printf(sorted:\n); for(i=1;i21;i++) printf(%d\t,a[i]); } 冒泡排序 快速排序 直接插入排序 希尔排序 选择排序 堆排序 归并排序 6.1.1 冒泡排序 算法描述 设待排序记录序列中的记录个数为n 一般地,第i趟起泡排序从1到n-i+1 依次比较相邻两个记录的关键字,如果发生逆序,则交换之 其结果是这n-i+1个记录中,关键字最大的记录被交换到第n-i+1的位置上,最多作n-1趟。 6.1.1 冒泡排序 算法实例 21 25 25* 16 08 0 1 2 3 4 5 21 25* 49 25 16 49 chang=1 08 25* chang=1 08 16 chang=1 25* 25 21 49 21 25 16 08 49 6.1.1 冒泡排序 算法实例 25* 0 1 2 3 4 5 i = 4 49 16 chang=1 08 25 21 25* i = 5 49 16 chang=0 08 25 21 6.1.1 冒泡排序 算法实例 21 08 25 49 25 16 21 49 25 25 16 08 21 49 25 25 16 08 21 49 25 25 16 08 21 49 25 25 16 08 21 49 25 25 16 08 初始关键字 第一趟排序 第四趟排序 第二趟排序 第三趟排序 第五趟排序 6.1.1 冒泡排序 算法实现 输入n 个数给a[1] 到 a[n] for j=1 to n-1 for i=1 to n-j a[i]a[i+1] 真 假 a[i]?a[i+1] 输出a[1] 到 a[n] #include stdio.h main() { int a[11],i,j,t; printf(Input 10 numbers:\n); for(i=1;i11;i++) scanf(%d,a[i]); printf(\n); for(j=1;j=9;j++) for(i=1;i=10-j;i++) if(a[i]a[i+1]) {t=a[i]; a[i]=a[i+1]; a[i+1]=t;} printf(The sorted numbers:\n); for(i=1;i11;i++) printf(%d ,a[i]); } 6.1.2 快速排序 算法特点: 快速排序是通过比较关键码、交换记录, 以某个记录为界(该记录称为支点)
您可能关注的文档
- 华海药业,海翔药业,九州药业项目环境影响.doc
- 做职业生涯规划详解.ppt
- 华科毕业论文模板.doc
- 重庆市梁平实验中学八级物理全册6.5科学探究摩擦力课件(新版)沪科版详解.ppt
- 华科第(电力拖动控制系统).ppt
- 做中学理念详解.ppt
- 华科第5(电力拖动控制系统).ppt
- 华科机械原理部分答案.pptx
- 华科级培养计划.doc
- 华科数据库实验报告.doc
- 2024-2025学年小学音乐二年级上册西师大版教学设计合集.docx
- 2024-2025学年初中美术七年级上册(2024)浙美版(2024)教学设计合集.docx
- 2024-2025学年小学信息技术(信息科技)五年级下册西师大版教学设计合集.docx
- 2024-2025学年初中化学九年级全册鲁教版(五四制)(2024)教学设计合集.docx
- 2024-2025学年小学劳动五年级下册人民版《劳动》(2022)教学设计合集.docx
- 2024-2025学年小学美术一年级上册(2024)赣美版(2024)教学设计合集.docx
- 2024-2025学年初中数学六年级上册沪教版(五四学制)(2024)教学设计合集.docx
- 2024-2025学年中职中职专业课林业类61 农林牧渔大类教学设计合集.docx
- 2024-2025学年初中地理七年级下册鲁教版(五四学制)(2024)教学设计合集.docx
- 2024-2025学年初中化学九年级下册鲁教版(2024)教学设计合集.docx
文档评论(0)