free Pascal 的排序习题

来源:百度知道 编辑:UC知道 时间:2024/06/01 00:53:56
简单排序和归并排序方面的习题! 谢!

给你一个快排,内部排序中最快的哦!(不稳定)
procedure kp(l,r:longint);
var i,j,x,t:longint;
begin
i:=l;j:=r;x:=a[(l+r) div 2];
repeat
while a[i]<x then inc(i);
while x<a[j] then dec(j);
if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t;inc(i);dec(j);end;
until i>j;
if i<r then kp(i,r);if l<j then kp(l,j);
end;

快排OK?