pascal-的排序整理_第1页
pascal-的排序整理_第2页
pascal-的排序整理_第3页
pascal-的排序整理_第4页
pascal-的排序整理_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

冒泡排序 Program Const infile sort in outfile sort out Var a Array 1 100000 of Longint f Boolean i n u Longint Begin Assign input infile Assign output outfile Reset input Rewrite output ReadLn n For i 1 To n Do Read a i Repeat f true For i 1 To n 1 Do If a i a i 1 Then Begin u a i a i a i 1 a i 1 u f false End Until f true For i 1 To n Do Write a i Close input Close output End 快排 Program Const infile sort in outfile qsort out Var a Array 1 1000000 Of Longint i n Longint Procedure quicksort l r Longint Var e x Integer i j Longint Begin i l j r x a Random r l 1 l Repeat While a i x Do Dec j If i j If l i Then quicksort i r End Begin Assign input infile Assign output outfile Reset input Rewrite output ReadLn n For i 1 To n Do Read a i quicksort 1 n For i 1 To n Do Write a i Close input Close output End 希尔排序 Program Const infile sort in outfile sort out Var a Array 1 1000000 of Integer t Boolean n jump i e Integer Begin Assign input infile Assign output outfile Reset input Rewrite output ReadLn N For i 1 To n Do Read a i jump n While jump 1 Do Begin jump jump div 2 Repeat t true For i 1 To n jump Do Begin If a i a i jump Then Begin e a i a i a i jump a i jump e t false End End until t true End For i 1 To n Do Write a i Close input Close output End 选择法排序 Program Const infile sort in outfile sort out Var j n i t Longint a Array 1 1000000 of Longint Begin Assign input infile Assign output outfile Reset input Rewrite output ReadLn n For i 1 To n DO Read a i For i 1 To n 1 Do For j i 1 To n Do If a i a j Then Begin t a i a i a j a j t End For i 1 To n Do Write a i Close input Close output End 冒泡法排序改进 两头 Program Const infile sort in outfile sort out Var a Array 1 1000000 OF Longint t I L R N R1 L1 Longint f Boolean Begin Assign input infile Assign output outfile Reset input Rewrite output ReadLn n For i 1 To n Do Read a i l 1 R n 1 Repeat f True For i l To r Do If a i a i 1 Then Begin t a i a i a i 1 a i 1 t f false r1 i End If f THen Break r r1 For i r Downto l 1 Do If a i a i 1 Then Begin t a i a i a i 1 a i 1 t l1 i 1 End l l1 Until f For i 1 To n Do Write a i Close input Close output End 基数法排序 Program Const infile sort in outfile sort out bin Array 1 9 Of Longint 1 10 100 1000 10000 100000 1000000 10000000 100000000 Function f x k Longint Longint Begin f x Div bin k mod 10 End Var c a Array 1 100000 Of Longint s Array 0 9 Of lOngint b Array 0 9 Of lOngint k j n i x1 x2 Longint Begin Assign input infile Assign output outfile Reset input Rewrite output ReadLn n k For i 1 To n Do Read a i For i 1 TO k Do Begin For j 0 to 9 dO b j 0 For j 1 To n Do Inc b f a j i s 0 b 0 For j 1 To 9 Do s j s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论