cs_SirJack
Messages postés9Date d'inscriptionvendredi 14 février 2003StatutMembreDernière intervention17 avril 2003
-
18 mars 2003 à 23:26
davidauche
Messages postés150Date d'inscriptionjeudi 20 mars 2003StatutMembreDernière intervention 8 janvier 2008
-
4 juin 2005 à 06:34
Je fais un jeux de loto et j'ai besoin de trier 6 chiffres en ordre croissant.
Montrer moi n,importe quel moyen s.v.p.
En étant très reconnaissant, Sir Jack
A voir également:
Trier liste python croissant
Ordre croissant python - Meilleures réponses
Python trier liste ordre croissant - Meilleures réponses
fredlynx
Messages postés662Date d'inscriptionmercredi 16 janvier 2002StatutModérateurDernière intervention16 octobre 20101 19 mars 2003 à 02:05
Un exemple de trie d'un tableau.... Un commandbutton donne ordre de trier un tableau de façon croisante ou décroissante au choix...
Private Sub Command1_Click()
Dim TabChiffre(5) As Integer
TabChiffre(0) = 8
TabChiffre(1) = 5
TabChiffre(2) = 40
TabChiffre(3) = 17
TabChiffre(4) = 2
TabChiffre(5) = 38
TrieTable TabChiffre(), True
End Sub
Private Function TrieTable(TabChiffre() As Integer, Croissant As Boolean)
Dim Boucle As Integer
Dim Vartmp As Integer
Boucle = 0
Do
Boucle = Boucle + 1
If (TabChiffre(Boucle) < TabChiffre(Boucle - 1)) And (Croissant = True) Then
Vartmp = TabChiffre(Boucle - 1)
TabChiffre(Boucle - 1) = TabChiffre(Boucle)
TabChiffre(Boucle) = Vartmp
Boucle = 0
ElseIf (TabChiffre(Boucle) > TabChiffre(Boucle - 1)) And (Croissant = False) Then
Vartmp = TabChiffre(Boucle - 1)
TabChiffre(Boucle - 1) = TabChiffre(Boucle)
TabChiffre(Boucle) = Vartmp
Boucle = 0
End If
Loop While Boucle < 5
End Function
pcpunch
Messages postés1247Date d'inscriptionmardi 7 mai 2002StatutMembreDernière intervention18 février 20195 19 mars 2003 à 02:13
slt
je suis debutant et j ai plancher sur la question, mais g pas était aussi rapide que fredlynx, mais bon je te met qd mm mon exemple. G pris une source de trie a bulle du site.
Tu place un bouton de command1 et 6 textbox(1 à 6) pour entrer tes nombres..
Dim TABLEAU(6) As Integer 'declare tableau avec 6 enregistrements
Dim BOL As Boolean
Private Sub Command1_Click()
'On entre la valeur des textbox ds le tableau
TABLEAU(1) = Text1.Text
TABLEAU(2) = Text2.Text
TABLEAU(3) = Text3.Text
TABLEAU(4) = Text4.Text
TABLEAU(5) = Text5.Text
TABLEAU(6) = Text6.Text
' TRI A BULLE du tableau dans l ordre croissant
For j = 1 To 6
DoEvents
BOL = False
For i = 1 To (6 - j)
If TABLEAU(i) > TABLEAU(i + 1) Then
BOL = True
Temp = TABLEAU(i)
TABLEAU(i) = TABLEAU(i + 1)
TABLEAU(i + 1) = Temp
End If
Next
If Not BOL Then j = 6
Next
'on affiche le resultat du tableau trié ds les textbox
Text1.Text = TABLEAU(1)
Text2.Text = TABLEAU(2)
Text3.Text = TABLEAU(3)
Text4.Text = TABLEAU(4)
Text5.Text = TABLEAU(5)
Text6.Text = TABLEAU(6)
End Sub
davidauche
Messages postés150Date d'inscriptionjeudi 20 mars 2003StatutMembreDernière intervention 8 janvier 2008 4 juin 2005 à 06:31
c'est juste pour corriger pcpunch, mais la méthode est parfaite.
pcpunch, quand tu declare un tableau(6) t'as 7 élements, ce n'est pas
le cas. les tableaux commencent par l'indice 0 et non
1.
voila le code après qlq modification. une procedure tri peut etre utiliser pour des autres tableaux avec n'importe taille.
Dim tableau(5) As Integer
Private Sub Command1_Click()
'On entre la valeur des textbox ds le tableau
tableau(0) = Text1.Text
tableau(1) = Text2.Text
tableau(2) = Text3.Text
tableau(3) = Text4.Text
tableau(4) = Text5.Text
tableau(5) = Text6.Text
' TRI A BULLE du tableau dans l ordre croissant
Call tri(tableau(), 6)
'on affiche le resultat du tableau trié ds les textbox
Text1.Text = tableau(0)
Text2.Text = tableau(1)
Text3.Text = tableau(2)
Text4.Text = tableau(3)
Text5.Text = tableau(4)
Text6.Text = tableau(5)
End Sub
Private Sub tri(t() As Integer, taille As Integer)
davidauche
Messages postés150Date d'inscriptionjeudi 20 mars 2003StatutMembreDernière intervention 8 janvier 2008 4 juin 2005 à 06:34
j'ai oublié qlq chose: la complexité de cette methode est enorme par
rapport a des autres algorithmes!!. mais bon! les vbistes s'en fou de
la complexité et la gestion de la mémoire.