type TLogical = type Boolean; TVariable = type Variant; class procedure PleaseSort(var _array:array of TVariable); var _improve_with_strings_and_objects___:TLogical; _i:LongInt; _j:LongInt; _k:LongInt; _stop:LongInt; _swap:TVariable; begin _stop := System.High(_array); _k := _stop shr 1;// div 2 while _k > Math.ZeroValue do begin for _i := Math.ZeroValue to _stop - _k do begin _j := _i; while (_j >= Math.ZeroValue) and (_array[_j] > _array[_j + _k]) // here is the test...!!! do begin _swap := _array[_j]; _array[_j] := _array[_j + _k]; _array[_j + _k] := _swap; if _j > _k then System.Dec(_j, _k) else _j := Math.ZeroValue; end; end; _k := _k shr 1; // div 2 end; end;
Remarque :
Voici, adaptée pour Delphi, un source trouvé sur le net !
Pas plus d'une page de code, et une des méthodes les plus efficaces de tri de tableau que je connaisse...
La ligne marquée du commentaire (here is the test) est la ligne de comparaison de deux éléments du tableau.
Utile...