QuickSort — List Version!

type
[...]
  TDirRecPointer=^TDirRec;
  TDirRec=record { subset of TSearchRec }
    Time: Integer;
    Size: Integer;
    Attr: Integer;
    Name: TFileName;
    Next: TDirRecPointer;
  end;

var
  root: TDirRecPointer;

function DRComp(a,b: TDirRec): integer;
{ Returns <0 if a<b
           0 if a=b
          >0 if a>b
}
[...]

procedure QuickSortLL(var a: TDirRecPointer);
var
  anow,anext,c,l,r,lastc: TDirRecPointer;
  DCRes: integer;
  function last(x: TDirRecPointer): TDirRecPointer;
  var y: TDirRecPointer;
  begin y:=x;
  while y^.next<>nil do y:=y^.next;
  last:=y;
  end;
begin
if (a=nil) or (a^.next=nil) then exit; { no elements, or only one }
c:=a; lastc:=a; anow:=a^.next; a^.next:=nil;
l:=nil; r:=nil;
repeat
  anext:=anow^.next;
  DCRes:=DRComp(c^,anow^);
  if DCRes=0 then
     begin
     anow^.next:=c; c:=anow;
     end { equal }
  else if DCRes<0 then
     begin
     anow^.next:=r; r:=anow;
     end { less }
  else begin
     anow^.next:=l; l:=anow;
     end; { greater }
  anow:=anext;
until anow=nil;
if l<>nil then QuickSortLL(l);
if r<>nil then QuickSortLL(r);
if l=nil then
   begin a:=c; lastc^.next:=r; end
else
   begin a:=l; anow:=last(a); anow^.next:=c;
   lastc^.next:=r; end;
end;