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: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
| procedure QuickSort(AGrid: TStringGrid;Spalte:Integer);
procedure QSort(LoIndex, HiIndex: Integer); var Lo, Hi: Integer; Pivot: Double; Swap: TStringList; f1,f2:Double; begin Swap := TStringList.Create; try if TryStrToFloat(AGrid.Cells[ Spalte,(LoIndex + HiIndex) div 2 ],Pivot) then begin Lo := LoIndex; Hi := HiIndex; repeat while TryStrToFloat(AGrid.Cells[ Spalte,lo],f1) and (f1 < Pivot) do Inc(Lo); while TryStrToFloat(AGrid.Cells[ Spalte,hi],f2) and (f2 > Pivot) do Dec(Hi); if Lo <= Hi then begin Swap.Assign (AGrid.Rows[lo]); AGrid.Rows[lo].Assign(AGrid.Rows[hi]); AGrid.Rows[hi].Assign(Swap); Inc(Lo); Dec(Hi); end; until Lo > Hi; if LoIndex < Hi then QSort(LoIndex, Hi); if Lo < HiIndex then QSort(Lo, HiIndex); end; finally Swap.Free; end; end; begin QSort(0, AGrid.RowCount - 1); end;
procedure QuickSort2(AGrid: TStringGrid;Spalte:Integer);
Function GetFloatCompare(const s:String;var F:Double):Boolean; begin if not TryStrToFloat(s,f) then f := - MaxInt; Result := true; end; procedure QSort(LoIndex, HiIndex: Integer); var Lo, Hi: Integer; Pivot: Double; Swap: TStringList; f1,f2:Double; begin Swap := TStringList.Create; try GetFloatCompare(AGrid.Cells[ Spalte,(LoIndex + HiIndex) div 2 ],Pivot); begin Lo := LoIndex; Hi := HiIndex; repeat while GetFloatCompare(AGrid.Cells[ Spalte,lo],f1) and (f1 < Pivot) do Inc(Lo); while GetFloatCompare(AGrid.Cells[ Spalte,hi],f2) and (f2 > Pivot) do Dec(Hi); if Lo <= Hi then begin Swap.Assign (AGrid.Rows[lo]); AGrid.Rows[lo].Assign(AGrid.Rows[hi]); AGrid.Rows[hi].Assign(Swap); Inc(Lo); Dec(Hi); end; until Lo > Hi; if LoIndex < Hi then QSort(LoIndex, Hi); if Lo < HiIndex then QSort(Lo, HiIndex); end; finally Swap.Free; end; end; begin QSort(0, AGrid.RowCount - 1); end; |