Einzelnen Beitrag anzeigen

striderx

Registriert seit: 11. Feb 2007
Ort: Bergisch Gladbach
206 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Quicksort-Rätsel

  Alt 12. Nov 2014, 15:36
Dann auf ein Neues:

Delphi-Quellcode:
procedure tdlgMain.SortData;

begin
  DataSort(1, TotalRecs);
end;

procedure tdlgMain.DataSort(Start, Stop: Word);

var
  pTemp: rCompRec;
  tStart: Word;
  tStop: Word;

begin
  tStart := Start;
  tStop := Stop;
  aData[0] := aData[(tStart + tStop) DIV 2];
  repeat
    while Less(tStart, 0) do Inc(tStart);
    while Less(0, tStop) do Dec(tStop);
    if tStart <= tStop then begin
       pTemp := aData[tStart];
       aData[tStart] := aData[tStop];
       aData[tStop] := pTemp;
       Inc(tStart);
       Dec(tStop);
    end;
  until tStart > tStop;
  if Start < tStop then DataSort(Start, tStop);
  if tStart < Stop then DataSort(tStart, Stop);
end;

function tdlgMain.Less(X, Y: Word): Boolean;

var
  R: Integer;
  S1: String;
  S2: String;

begin
  if (aData[X].Deleted = False) and (aData[Y].Deleted = True) then begin
     Result := True;
     Exit;
  end
  else if (aData[X].Deleted = True) and (aData[Y].Deleted = False) then begin
     Result := False;
     Exit;
  end;
  if (aData[X].RecType) < (aData[Y].RecType) then begin
     Result := True;
     Exit;
  end
  else if (aData[X].RecType) > (aData[Y].RecType) then begin
     Result := False;
     Exit;
  end;
  Result := False;
  case aData[X].RecType of
     1: begin
          S1 := GetArtistSurname(aData[X].wlIndexArtist);
          S2 := GetArtistSurname(aData[Y].wlIndexArtist);
          R := AnsiCompareText(S1, S2);
          if R < 0 then Result := True
          else if R = 0 then begin
             S1 := GetArtistFirstName(aData[X].wlIndexArtist);
             S2 := GetArtistFirstName(aData[Y].wlIndexArtist);
             R := AnsiCompareText(S1, S2);
             if R < 0 then Result := True
             else if R = 0 then begin
                S1 := aData[X].wlNameofWork;
                S2 := aData[Y].wlNameofWork;
                if AnsiCompareText(S1, S2) < 0 then Result := True
             end;
          end;
        end;
     2: begin
          S1 := aData[X].arSurname;
          S2 := aData[Y].arSurname;
          R := AnsiCompareText(S1, S2);
          if R < 0 then Result := True
          else if R = 0 then begin
             S1 := aData[X].arFirstName;
             S2 := aData[Y].arFirstName;
             if AnsiCompareText(S1, S2) < 0 then Result := True
          end;
        end;
     3: begin
          if (aData[X].hoDate <> 0) and (aData[Y].hoDate = 0)
             then Result := True
          else if (aData[X].hoDate = 0) and (aData[Y].hoDate <> 0)
             then Result := False
          else if (aData[X].hoDate = 0) and (aData[Y].hoDate = 0)then begin
                if aData[X].hoIndexHolidays < aData[Y].hoIndexHolidays
                   then result := True;
          end
          else if aData[X].hoDate < aData[Y].hoDate then Result := True;
        end;
     4: begin
          S1 := aData[X].cuSurname;
          S2 := aData[Y].cuSurname;
          R := AnsiCompareText(S1, S2);
          if R < 0 then Result := True
          else if R = 0 then begin
             S1 := aData[X].cuFirstName;
             S2 := aData[Y].cuFirstName;
             if AnsiCompareText(S1, S2) < 0 then Result := True
          end;
        end;
     5: begin
          S1 := aData[X].saArticle;
          S2 := aData[Y].saArticle;
          if AnsiCompareText(S1, S2) < 0 then Result := True
        end;
     6: if aData[X].prIndexPrices < aData[Y].prIndexPrices then Result := True;
     7: begin
          S1 := aData[X].emSurname;
          S2 := aData[Y].emSurname;
          R := AnsiCompareText(S1, S2);
          if R < 0 then Result := True
          else if R = 0 then begin
             S1 := aData[X].emFirstName;
             S2 := aData[Y].emFirstName;
             if AnsiCompareText(S1, S2) < 0 then Result := True
          end;
        end;
  end;
end;
  Mit Zitat antworten Zitat