简化的pascal快速排序代码

来源:百度知道 编辑:UC知道 时间:2024/06/11 16:02:35
要求对一般教材的代码有大幅度简化,目的是便于记忆

我背的就是这个,特别好用,还好记。
procedure quicksort(l,r:longint);
var
__x,i,j,t :longint;
begin
__x:=a[random(r-l+1)+l];
__i:=l;j:=r;

__repeat
____while a[i]<x do inc(i);
____while a[j]>x do 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 l<j then quicksort(l,j);
__if i<r then quicksort(i,r);
end;

记得要 randomize