Ich hatte auch mal so ein ähnliches Problem: Ich musste so einen Array sortieren. Ich habs damals so gelöst:
Delphi-Quellcode:
procedure tausche (var a, b : integer);
VAR hilf : integer;
Begin
hilf := a;
a := b;
b := hilf;
end;
// Tliste = array of array[0..1] of integer;
// TErgebnisListe = array of integer;
function Loesungssystem.sort(Eingabe : Tliste ; n1 : integer) : TErgebnisListe;
VAR x,y,i : integer;
tausch : boolean;
e : tergebnisliste;
Begin
y := n1;
tausch := true;
While tausch do
Begin
tausch := false;
For x := 0 to y -1 do
If Eingabe[x,1] > Eingabe[x+1,1] then
Begin
tausch := true;
tausche (Eingabe[x,1], Eingabe[x+1,1]);
tausche (Eingabe[x,0], Eingabe[x+1,0]); // andere Reihe wird mitsortiert
End;
y := pred(y);
End;
setlength(e,length(eingabe));
for i := 0 to high(Eingabe) do
e[i] := eingabe[i,0];
result := e; // Die Reihenfolge der Vorkommen als ARRAY
End;
Müsste man noch entsprechend umbauen... und jenach dem noch zusätzliche Bedingungen einführen...