function sort( r : list ) : list;
var head, tail : array[1..M] of list;
i, j, h : integer;
begin
for i:=D downto 1 do begin
for j:=1 to M do head[j] := nil;
while r <> nil do begin
h := charac( i, r^.k );
if head[h]=nil then head[h] := r
else tail[h]^.next := r;
tail[h] := r;
r := r^.next;
end;
{*** Concatenate lists ***}
r := nil;
for j:=M downto 1 do
if head[j] <> nil then begin
tail[j]^.next := r;
r := head[j]
end
end;
sort := r
end;
|