BubbleSort sortiert und CountString und zählt die einzelnen
IP Elemente zusammen.
Bsp : 192 + 168 + 0 + 1 < 192 + 168 + 0 + 15
Delphi-Quellcode:
function CountString (Str:String) : Byte;
var
i: Integer;
begin
Result := 0;
i := 1;
while Length(Str) > 0 do
if Str[i] = '.' then
begin
Result := StrToInt(Copy(Str, 1, i - 1)) + Result;
Str := Copy(Str, i + 1, Length(Str) - i);
i := 1;
end else
begin
Inc(i);
if Length(Str) < i then
begin
Result := Result + StrToInt(Str);
Break;
end;
end;
end;
procedure BubbleSort(var Items: TStringList);
var
done: Boolean;
i, n, i0, i1 : integer;
Dummy: string;
begin
n := Items.Count;
Done := False;
while not (done) do
begin
done := true;
for i := 0 to n - 2 do
begin
i0 := CountString(Items[i]);
i1 := CountString(Items[i+1]);
if (i1 < i0) then
begin
Dummy := Items[i+1];
Items[i+1] := Items[i];
Items[i] := Dummy;
Done := False
end;
end;
end;
end;
[edit=Matze]Code formatiert. Mfg, Matze[/edit]