Tri décroissant de flottants?

Résolu
XgaletteX Messages postés 102 Date d'inscription samedi 14 mai 2005 Statut Membre Dernière intervention 12 août 2005 - 19 mai 2005 à 14:13
cs_Kenavo Messages postés 702 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 1 octobre 2009 - 19 mai 2005 à 14:59
Bonjour,

Es ce que quelqu'un aurai un algo permettant de faire le tri de flottant par ordre décroissant?

2 réponses

cs_Kenavo Messages postés 702 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 1 octobre 2009 5
19 mai 2005 à 14:59
J'avais oublié un bout !



procedure TForm1.Sort(var A: array of Double);



procedure QuickSort(var A: array of Double; iLo, iHi: Integer);

var

Lo, Hi : Integer;

Mid, T : Double;

begin

Lo := iLo;

Hi := iHi;

Mid := A[(Lo + Hi) div 2];

repeat

while A[Lo] > Mid do Inc(Lo);

while A[Hi] < Mid do Dec(Hi);

if Lo < = Hi then

begin

T := A[Lo];

A[Lo] := A[Hi];

A[Hi] := T;

Inc(Lo);

Dec(Hi);

end ;

until Lo > Hi;

if Hi > iLo then QuickSort(A, iLo, Hi);

if Lo < iHi then QuickSort(A, Lo, iHi);

end;



begin

QuickSort(A, Low(A), High(A));

end;





Ken@vo

<hr size ="2" width="100%">Code, Code, Codec !




http://www.pourflorenceethussein.org/

[%3C/body ]
3
cs_Kenavo Messages postés 702 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 1 octobre 2009 5
19 mai 2005 à 14:56
Tu peux t'inspirer des algo de tri présenté dans \Program File\Borland\Delphi x\Demos\Threads\Thorthds.pas



Il y a jute a remplacer le tableau d'entiers par un tableau de réels et
certaines variables entières en réels, et retourner l'ordre des
comparaisons pour un tri drécroissant



Par exemple pour le QuickSort:



procedure TForm1.Sort(var A: array of Double);



procedure QuickSort(var A: array of Double; iLo, iHi: Integer);

var

Lo, Hi : Integer;

Mid, T : Double;

begin

Lo := iLo;

Hi := iHi;

Mid := A[(Lo + Hi) div 2];

repeat

while A[Lo] > Mid do Inc(Lo);

while A[Hi] < Mid do Dec(Hi);

if Lo < = Hi then

begin

T := A[Lo];

A[Lo] := A[Hi];

A[Hi] := T;

Inc(Lo);

Dec(Hi);

end ;

until Lo > Hi;

if Hi > iLo then QuickSort(A, iLo, Hi);

if Lo < iHi then QuickSort(A, Lo, iHi);

end;





Ken@vo


<hr size ="2" width="100%">Code, Code, Codec !




http://www.pourflorenceethussein.org/

[%3C/body ]
0
Rejoignez-nous