AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Array of Array of string Quicksort

Ein Thema von cherry · begonnen am 12. Jan 2010 · letzter Beitrag vom 8. Nov 2010
 
Benutzerbild von cherry
cherry

Registriert seit: 14. Nov 2005
561 Beiträge
 
RAD-Studio 2009 Ent
 
#5

AW: Array of Array of string Quicksort

  Alt 8. Nov 2010, 09:01
QuickSortStringArray2Ex(StringArrQuota,0,Length(StringArrQuota)-1,SortedCol);
Delphi-Quellcode:
{******************************************************************************}
// QUICK SORT STRING ARRAY 2 EXTENDED (multidimensional)
// Extended in this case: The values will be compared UPPERCASE, a < B
// http://en.wikibooks.org/wiki/Algorithm_Implementation/Sorting/Quicksort#Delphi
{******************************************************************************}
procedure QuickSortStringArray2Ex(var A: TStringArray2; L, R: Integer; SortCol: Integer);
var
  OrigL,
  OrigR: Integer;
  Pivot: string;
  GoodPivot,
  SortPartitions: Boolean;
  tmp: TStringArray;
begin
  if L<R then begin
    Pivot:=UPPERCASE(A[L+Random(R-L),SortCol]);
    OrigL:=L; //saving original bounds
    OrigR:=R;
    repeat
      L:=OrigL; //restoring original bounds if we
      R:=OrigR; //have chosen a bad pivot value
      while L<R do begin
        while (L<R) and (UPPERCASE(A[L,SortCol])<Pivot) do Inc(L);
        while (L<R) and (UPPERCASE(A[R,SortCol])>=Pivot) do Dec(R);
        if (L<R) then begin
          tmp:=A[L];
          A[L]:=A[R];
          A[R]:=tmp;
          Dec(R);
          Inc(L);
        end;
      end;
      if UPPERCASE(A[L,SortCol])>=Pivot then Dec(L); //has we managed to choose
      GoodPivot:=L>=OrigL; //a good pivot value?
      SortPartitions:=True; //if so, then sort on
      if not GoodPivot then begin //bad luck, the pivot is the smallest one in our range
        GoodPivot:=True; //let's presume that all the values are equal to pivot
        SortPartitions:=False; //then no need to sort it
        for R := OrigL to OrigR do if UPPERCASE(A[R,SortCol])<>Pivot then begin //we have at least one different value than our pivot
          Pivot:=UPPERCASE(A[R,SortCol]); //so this will be our new pivot
          GoodPivot:=False; //we have to start again sorting this range
          Break;
        end;
      end;
    until GoodPivot;
    if SortPartitions then begin
      QuickSortStringArray2Ex(A, OrigL, L, SortCol);
      QuickSortStringArray2Ex(A, L+1, OrigR, SortCol);
    end;
  end;
end;
Ist das nur mein Gefühl, oder ist die ganze Welt verrückt geworden!?
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz