- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
pascal排序算法.ppt
42 220 41 185 242 190 225 231 i=1 j=7 42 220 41 185 242 190 225 231 i=2 j=6 42 220 41 185 242 190 225 231 i=2 j=5 42 220 41 185 242 190 225 231 i=2 j=4 42 185 41 220 242 190 225 231 i=2 j=4 42 185 41 220 242 190 225 231 i=3 j=3 42 185 41 220 242 190 225 231 i=4 j=3 42 185 41 220 242 190 225 231 i=4 j=3 L..j i..R const maxn=100000; fin=sort.in; fout=sort.out; var a:array[1..maxn] of longint; n:longint; procedure init; var i:longint; begin assign(input,’f.in’); reset(input); readln(n); for i:=1 to n do read(a[i]); close(input); end; procedure qsort(head,tail:longint); var i,j,mid,tem:longint; begin i:=head; j:=tail; mid:=a[(head+tail)div2]; while i=j do begin while a[i]mid do inc(i); while a[j]mid do dec(j); if i=j then begin tem:=a[i]; a[i]:=a[j]; a[j]:=tem; inc(i); dec(j); end; end; if headj then qsort(head,j); if itail then qsort(i,tail); end; procedure print; var i:longint; begin assign(output,fout); rewrite(output); for i:=1 to n-1 do write(a[i], ); writeln(a[n]); close(output); end; begin init; qsort(1,n); print; end. 随机快排 program qsortsortpro; const max=10000; var n,i:longint; a:array[1..max]of longint; procedure qsort(head,tail:longint); var i,j,x,t:longint; begin i:=head; j:=tail; x:=a[random(tail-head+1)+head]; //随机选取参考值 head—tail while ij do begin while a[i]x do inc(i); while xa[j] do dec(j); if (i=j) then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); end; end; if headj then qsort(head,j); if itail then qsort(i,tail); end; begin readln(n); randomize; for i:=1 to n do read(a[i]); qsort(1,n); for i:=1 to n do writeln(a[i]); end. 取首快排 program quicksort; const mx=10000; var n,i:longint; d:array[1..mx]of longint; procedure qsort(he
您可能关注的文档
最近下载
- 《建筑与市政工程施工现场临时用电安全技术标准JGJT46-2024》知识培训.pptx VIP
- 5G+虚拟现实开发应用赛项理论备考试题库(含答案).docx VIP
- T_CAWAORG 014—2024(老年综合评估及干预技术应用规范).pdf VIP
- 甘肃省武威市凉州区第十中学2024-2025学年九年级上学期第一次月考数学试卷.docx VIP
- 基于JX-300XP的板式精馏塔DCS控制系统的设计.doc VIP
- 装饰合同封面.doc VIP
- PLC的全自动工业洗衣机系统方案设计课程方案设计说明书.doc VIP
- 2023年陕西邮电职业技术学院教师招聘考试题库及答案解析.docx VIP
- (新人教版)音乐一年级上册 全册教学课件.pptx
- 2024年广东省专升本英语考试真题及答案7257.pdf VIP
文档评论(0)