Thema: ReverseString

Einzelnen Beitrag anzeigen

Benutzerbild von mleyen
mleyen

Registriert seit: 10. Aug 2007
609 Beiträge
 
FreePascal / Lazarus
 
#7

AW: ReverseString

  Alt 24. Feb 2011, 08:37
Delphi-Quellcode:
  procedure QSortStr(var AStr: string);
  var
    tmp: Char;

    procedure QSortAll(const LoIndex, HiIndex: Integer);
    var
      Lo, Hi: Integer;
      Pivot: Integer;
    begin
      Lo := LoIndex;
      Hi := HiIndex;
      Pivot := StrToInt(AStr[(Lo + Hi) div 2]);

      repeat
        while StrToInt(AStr[Lo]) < Pivot do
          Inc(Lo);
        while StrToInt(AStr[Hi]) > Pivot do
          Dec(Hi);
        if Lo <= Hi then
        begin
          if Lo < Hi then
            if AStr[Lo] <> AStr[Hi] then
            begin
              tmp := AStr[Lo];
              AStr[Lo] := AStr[Hi];
              AStr[Hi] := tmp;
            end;
          Inc(Lo);
          Dec(Hi);
        end;
      until Lo > Hi;

      if LoIndex < Hi then
        QSortAll(LoIndex, Hi);
      if Lo < HiIndex then
        QSortAll(Lo, HiIndex);
    end;

  begin
    if Length(AStr) > 0 then
      QSortAll(1, Length(AStr));
  end;

  function getQSortedStr(const AStr: string): string;
  begin
    Result := AStr;
    QSortStr(Result);
  end;

Geändert von mleyen (24. Feb 2011 um 09:23 Uhr)
  Mit Zitat antworten Zitat