1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| int compare(TMyGrid *Grille1, int SortCol, int row1, int row2);
int comparebis(TMyGrid *Grille1, int SortCol, int row1, int row2);
void __fastcall swap(TMyGrid *Grille1, int SortCol, int row1, int row2);
void __fastcall quicksort(TMyGrid *Grille1, int col, int bottom, int top,
int (&fcomp)(TMyGrid *Grille1, int SortCol, int row1, int row2));
void __fastcall quicksort(TMyGrid *Grille1, int col, int bottom, int top,
int (&fcomp)(TMyGrid *Grille1, int SortCol, int row1, int row2))
{ int up, down, pivot;
String s;
down = top;
up = bottom;
pivot = (top + bottom) / 2;
do
{ //while (compare(Grille1, col, up, pivot) < 0) up++;
while (fcomp(Grille1, col, up, pivot) < 0) up++;
//while (compare(Grille1, col, down, pivot) > 0) down--;
while (fcomp(Grille1, col, down, pivot) < 0) down--;
if (up <= down)
{swap(Grille1, col, up, down);
if (pivot == up)
pivot = down;
else if (pivot == down)
pivot = up;
up++;
down--;
};
} while (up<=down); // until up > down;
if (bottom < down)
quicksort(Grille1,col, bottom, down, fcomp);
if (up < top)
quicksort(Grille1,col, up, top, fcomp);
}
Appel du tri:
quicksort(Grille1,1,1,Grille1->RowCount,compare); |
Partager