// Aufruf:
// QuickSortColumn(StringGrid1, Col, StringGrid1->FixedRows, StringGrid1->RowCount - 1, CheckBox1->Checked);
void __fastcall TForm1::QuickSortColumn(TStringGrid *grid, int Column, int links, int rechts, bool Desc)
{
// rechte und linke grenze festlegen
int i = links;
int j = rechts;
// den mittelwert bestimmen (sortierung aufteilen)
int m = StrToInt(grid->Cells[Column][(int) ((links + rechts) / 2)]);
do
{
// sortier-reihenfolge festlegen
while (Desc ? (StrToInt(grid->Cells[Column][i]) < m) : (StrToInt(grid->Cells[Column][i]) > m)) i++;
while (Desc ? (m < StrToInt(grid->Cells[Column][j])) : (m > StrToInt(grid->Cells[Column][j]))) j--;
if (i <= j)
{
// Zeilen tauschen
AnsiString tmp = grid->Rows[i]->CommaText;
grid->Rows[i]->CommaText = grid->Rows[j]->CommaText;
grid->Rows[j]->CommaText = tmp;
i++;
j--;
}
}
while (i < j);
// rekursiver aufruf
if (links < j) QuickSortColumn(grid, Column, links, j, Desc);
if (i < rechts) QuickSortColumn(grid, Column, i, rechts, Desc);
}