Tri d'un tableau par la méthode "a Bulle"

Tri d'un tableau par la méthode "a Bulle"

Messagepar Michael DELIQUE » 22 Fév 2008 à 11:54

Code : Tout sélectionner
Sub SortBubble(vrTable As Variant)
   
   'Tri à bulle par ordre croissant
   
   'Déclaration Variables
   Dim nbUBound As Long
   Dim nbLbound As Long
   Dim i As Long
   Dim J As Long
   Dim vrValue As Variant
   
   On Error Goto ErreurHandle
   
   nbLbound = Lbound(vrTable)
   nbUBound = Ubound(vrTable)
   
   If nbUBound = nbLbound Then
      'si 1 seule donnée pas de traitement
      Exit Sub
   Elseif nbUBound = (nbLbound+1) Then
      'si uniquement 2 données
      If  vrTable(nbLbound) >  vrTable(nbUBound) Then
         vrValue = vrTable(nbUBound)
         vrTable(nbUBound) = vrTable(nbLbound)
         vrTable(nbLbound) = vrValue
         vrValue = Null
      End If
      Exit Sub
   End If
   
   'Tri du tableau
   For i=nbLbound To nbUBound-1
      J = i
      While (J>=i)
         If vrTable(J+1) < vrTable(J) Then
            vrValue = vrTable(J)
            vrTable(J) = vrTable(J+1)
            vrTable(J+1) = vrValue
         End If
         J = J-1
      Wend
   Next
   vrValue = Null
   
   Exit Sub
ErreurHandle:
   Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   Exit Sub
End Sub
Dernière édition par Michael DELIQUE le 23 Fév 2008 à 23:05, édité 1 fois.
Cordialement

Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy

Messagepar oguruma » 23 Fév 2008 à 09:34

la plus simple et la plus rapide pour des faibles volumes
Bien à vous

http://www.dominoarea.org/oguruma/

Les téléphones PORTABLES dans les TGV y en a MARRRE de ces voyageurs qui ne respectent pas les autres ! ARRET DES PORTABLES SVP - Merci

Fumeurs ! respectez les non fumeurs !!!
Fumeurs ! respectez la loi de février 2007 et les lieux publics !!! (ie. hall de gares)
Avatar de l’utilisateur
oguruma
Super V.I.P.
Super V.I.P.
 
Message(s) : 4086
Inscrit(e) le : 16 Déc 2004 à 08:50
Localisation : LILLE


Retour vers Fonctions de tris