快速排序法

来源:百度知道 编辑:UC知道 时间:2024/05/31 03:52:01
求快速排序法实现方法,代码

procedure qsort(var a : arrtype);

procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;

数据结构学的吗 我有书 但是太多 建议看 清华大学出版的 数据结构 51页