qsort的标准程序在demo\text\qsort.pp中有,以下是一个稳定的qsort
type tlist=array[0..max]of longint;
procedure qsort(var a : tlist);
    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<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a;
                a:=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;
    begin
       sort(1,a[0]);
    end;
使用时,只须const max的值
须调用时写一句qsort(a)即可
注:a为须排序的数组,a[0]表示a的长度