type
tPerson =
record
FNachName:
String;
FGroesse: Double;
FAlter: Word;
end;
var
aPersons:
Array of tPerson;
SortMode: Word = 1;
...
SetLength(aPersons, N + 1];
//+ 1 wg. des Elements 0
procedure SortPersons;
//Insertion-Sort
var
I: Word;
J: Word;
begin
for I := 1
to Length(aPersons) - 1
do begin
J := I;
aPersons[0] := aPersons[I];
while (J > 0)
and (Less(aPersons[0], aPersons[J - 1]))
do begin
aPersons[J]:= aPersons[J - 1];
Dec(J);
end;
aPersons[J]:= aPersons[0];
end;
end
function Less(X, Y: Word): Boolean;
var
R: Integer;
begin
Result := False;
case SortMode
of
1:
begin
R := AnsiCompareText(aPersons[X].FNachname, aPersons[Y].FNachname);
if R < 0
then Result := True
else if R = 0
then begin
if aPersons[X].FAlter < aPersons[Y].FAlter
then Result := True
else if aPersons[X].FAlter = aPersons[Y].FAlter
then begin
if aPersons[X].Groesse < aPersons[Y].FGroesse
then Result := True;
end;
end;
2:
begin
...
end;
3:
begin
...
end;
end;