Adapter Tri rapide (quickSort) pour listbox
Bonjour
J'ai un liste de donnée qui s'affiche dans une listbox
Mon code fonction, avec la liste non triée, mais lorsque je veux la trier
à partir d'un bouton, le tri ne fonction pas.
ou est le problème ?
merci d'avance
Code:
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
|
Private Sub UserForm_Activate()
Dim Tb, Ii, Ij
Dim TabListBox As Variant
Dim i, j, k, l As Byte
Dim temp As String
Tb = TableClient.Range("A2:C" & TableClient.Range("A" & TableClient.Rows.Count).End(xlUp).Row)
With Me.ListBox1
.ColumnCount = 2
.ColumnWidths = "45;100"
For i = LBound(Tb, 1) To UBound(Tb, 1)
If Tb(i, 1) = "Oui" Then 'sélectionne les lignes avec en colonne A de ma table T_client qui correspondent à la valeur "Oui"
.AddItem Tb(i, 2)
.List(.ListCount - 1, 1) = Tb(i, 3)
j = j + 1
End If
Next i
nd With
' Tri par libellé le plan des comptes clients Correspond à colonne B de ma table
' je rajoute l'appel à quicksort 'ancien amplement de mon tri par bulle trop long
'
Call QUICKSORT(t(), loBound(t), upBound(t)) 'Proc récursive
End Sub |
Le mode standard
Code:
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
|
Public Sub QUICKSORT(t() As Long, _
ByVal loBound As Long, _
ByVal upBound As Long)
Dim med_value As Long
Dim hi As Long
Dim lo As Long
Dim i As Long
If loBound >= upBound Then Exit Sub
i = Int((upBound - loBound + 1) * Rnd + loBound)
med_value = t(i)
t(i) = t(loBound)
lo = loBound
hi = upBound
Do
Do While t(hi) >= med_value
hi = hi - 1
If hi <= lo Then Exit Do
Loop
If hi <= lo Then
t(lo) = med_value
Exit Do
End If
t(lo) = t(hi)
lo = lo + 1
Do While t(lo) < med_value
lo = lo + 1
If lo >= hi Then Exit Do
Loop
If lo >= hi Then
lo = hi
t(hi) = med_value
Exit Do
End If
t(hi) = t(lo)
Loop
' Recursive calls
QUICKSORT t(), loBound, lo - 1
QUICKSORT t(), lo + 1, upBound
End Sub |