Boostez vos compétences Excel avec notre communauté !
Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !
oui mais c'est quoi que tu as mis à jour exactementj'ai mis la source a jour
Sub createliste()
ReDim t(1 To 20000, 1 To 1)
Cells(1, 1).CurrentRegion.ClearContents
For i = 1 To 20000
t(i, 1) = Int(1 + (Rnd * 30000))
Next
Cells(1, 1).Resize(20000) = t
Cells(1.1).Resize(20000).RemoveDuplicates Columns:=1, Header:=xlNo
Cells(10001, 1).Resize(20000).ClearContents
End Sub
Sub creatliste2()
Dim t
[A:A].ClearContents
t = Evaluate("ROW(1:10000)")
For i = 1 To UBound(t)
x = Int(1 + (Rnd * 10000))
tp = t(i, 1): t(i, 1) = t(x, 1): t(x, 1) = tp
Next
Cells(1, 1).Resize(10000) = t
End Sub
Sub test()
Dim Tdon, tim#
Tdon = Application.Transpose([A1].CurrentRegion.Value)
tim = Timer
PartitAmél Tdon, 1, 10000
MsgBox Format(Timer - tim, "#0.00") & "sec"
Cells(1, 3).Resize(10000) = Application.Transpose(Tdon)
End Sub
Private Sub PartitAmél(Tdon, ByVal Min As Long, ByVal Max As Long)
Dim VPiv, Crs As Long, Dcr As Long, V, _
R As Long, Arg, Mn As Long, Mx As Long, S As Long
If Max - Min > 20 Then
VPiv = Tdon(Min + Int(Rnd * (Max - Min + 1)))
Crs = Min: Dcr = Max
Do While Crs <= Dcr
Do While Tdon(Crs) < VPiv: Crs = Crs + 1: Loop
Do While VPiv < Tdon(Dcr): Dcr = Dcr - 1: Loop
If Crs <= Dcr Then
V = Tdon(Crs): Tdon(Crs) = Tdon(Dcr): Tdon(Dcr) = V
Crs = Crs + 1: Dcr = Dcr - 1
End If
Loop ' While Crs <= Dcr
If Crs < Max Then PartitAmél Tdon, Crs, Max
If Min < Dcr Then PartitAmél Tdon, Min, Dcr
Else
For R = Min + 1 To Max: Arg = Tdon(R)
Mn = Min: Mx = R
Do: S = (Mn + Mx) \ 2
If Tdon(S) <= Arg Then Mn = S + 1 Else Mx = S
Loop Until Mx <= Mn
For S = R To Mn + 1 Step -1: Tdon(S) = Tdon(S - 1): Next S
Tdon(S) = Arg
Next R
End If
End Sub
le fichier et la vidéooui mais c'est quoi que tu as mis à jour exactement
Sub createliste()
ReDim t(1 To 20000, 1 To 1)
Cells(1, 1).CurrentRegion.ClearContents
For i = 1 To 20000
t(i, 1) = Int(1 + (Rnd * 30000))
Next
Cells(1, 1).Resize(20000) = t
Cells(1.1).Resize(20000).RemoveDuplicates Columns:=1, Header:=xlNo
Cells(10001, 1).Resize(20000).ClearContents
End Sub
Sub creatliste2()
Dim t
[A:A].ClearContents
t = Evaluate("ROW(1:10000)")
For i = 1 To UBound(t)
x = Int(1 + (Rnd * 10000))
tp = t(i, 1): t(i, 1) = t(x, 1): t(x, 1) = tp
Next
Cells(1, 1).Resize(10000) = t
End Sub
Sub test()
Dim Tdon, tim#
Tdon = Application.Transpose([A1].CurrentRegion.Value)
tim = Timer
SortDichotomique Tdon, 1, 10000
MsgBox Format(Timer - tim, "#0.00") & "sec"
Cells(1, 3).Resize(10000) = SortDichotomique(Tdon)
End Sub
Function SortDichotomique(Tdon, Optional ByVal Min As Long = -1, Optional ByVal Max As Long = -1)
Dim VPiv, Crs As Long, Dcr As Long, V, R As Long, Arg, Mn As Long, Mx As Long, S As Long
If Min = -1 Then Min = LBound(Tdon)
If Max = -1 Then Max = UBound(Tdon)
For R = Min + 1 To Max: Arg = Tdon(R)
Mn = Min: Mx = R
Do: S = (Mn + Mx) \ 2
If Tdon(S) <= Arg Then Mn = S + 1 Else Mx = S
Loop Until Mx <= Mn
For S = R To Mn + 1 Step -1: Tdon(S) = Tdon(S - 1): Next S
Tdon(S) = Arg
Next R
SortDichotomique = Application.Transpose(Tdon)
End Function
'******************************************************************************************************************************************************
' ___ __ _ _ _ __ ____ ___
' // || // \\ /\\ //| // // \\ // // \\
' // || //__// //__\ // | // //__// //__ //_ //
' // // // \\ // \\ // | // // \\ // // \\
'//___// // // // //// |// // // //___ //____//
'******************************************************************************************************************************************************
'méthode 7
'Auteur Dranreb sur Exceldownloads
'date:11/11/2023
'rédigé sous la forme d'une fonction par patricktoulon
'principe utilisé :recherche dichotomique
'fait partie des principes dit avec Pivot
'on va prendre comme pivot le milieu et on va tester le mileu dela partie du debut a la fin correspondant au milieu de l'array entier
'si on trouve on deplace sinon on recommence en augmentant la min +1
'une autre boucle faire le bubble de r= mn par pas de -1
'le tout dans une boucle répéteuse de lbound+1 a max
Dim Q&, Ch&
Sub createliste() 'liste avec manquant
ReDim t(1 To 20000, 1 To 1)
Cells(1, 1).CurrentRegion.ClearContents
For i = 1 To 20000
t(i, 1) = Int(1 + (Rnd * 30000))
Next
Cells(1, 1).Resize(20000) = t
Cells(1.1).Resize(20000).RemoveDuplicates Columns:=1, Header:=xlNo
Cells(10001, 1).Resize(20000).ClearContents
End Sub
Sub creatliste2() 'liste sans manquants
Dim t
[A:A].ClearContents
t = Evaluate("ROW(1:10000)")
For i = 1 To UBound(t)
x = Int(1 + (Rnd * 10000))
tp = t(i, 1): t(i, 1) = t(x, 1): t(x, 1) = tp
Next
Cells(1, 1).Resize(10000) = t
End Sub
Sub test()
Dim Tdon, tim#
Tdon = Application.Transpose([A1].CurrentRegion.Value)
tim = Timer
Tdon = SortDichotomique(Tdon)
msg = Format(Timer - tim, "#0.00") & " secondes" & vbCrLf & Q & " tours de boucle" & vbCrLf & Ch & " interversions"
Cells(1, 3).Resize(UBound(Tdon)) = Tdon
#If Not Mac Then
Application.Speech.Speak msg, True
#End If
MsgBox msg
End Sub
Function SortDichotomique(Tdon, Optional ByVal Min As Long = -1, Optional ByVal Max As Long = -1)
Dim VPiv, Crs As Long, Dcr As Long, V, R As Long, Arg, Mn As Long, Mx As Long, S As Long
If Min = -1 Then Min = LBound(Tdon)
If Max = -1 Then Max = UBound(Tdon)
For R = Min + 1 To Max: Arg = Tdon(R)
Mn = Min: Mx = R
Do: S = (Mn + Mx) \ 2
If Tdon(S) <= Arg Then Mn = S + 1 Else Mx = S
Q = Q + 1
Loop Until Mx <= Mn
For S = R To Mn + 1 Step -1: Tdon(S) = Tdon(S - 1): Q = Q + 1: Ch = Ch + 1: Next S
Tdon(S) = Arg
Next R
SortDichotomique = Application.Transpose(Tdon)
End Function
Function SortDichotomique(Tdon, Optional ByVal Min As Long = -1, Optional ByVal Max As Long = -1)
Dim VPiv, Crs As Long, Dcr As Long, V, R As Long, Arg, Mn As Long, Mx As Long, S As Long
If Min = -1 Then Min = LBound(Tdon)
If Max = -1 Then Max = UBound(Tdon)
For R = Min + 1 To Max: Arg = Tdon(R)
Mn = Min: Mx = R
Do: S = (Mn + Mx) \ 2
If Tdon(S) <= Arg Then Mn = S + 1 Else Mx = S
Loop Until Mx <= Mn
For S = R To Mn + 1 Step -1: Tdon(S) = Tdon(S - 1): Next S
Tdon(S) = Arg
Next R
SortDichotomique = Tdon
End Function
'Function SortDichotomique(Tdon, Optional ByVal Min As Long = -1, Optional ByVal Max As Long = -1)
' Dim VPiv, Crs As Long, Dcr As Long, V, R As Long, Arg, Mn As Long, Mx As Long, S As Long
' If Min = -1 Then Min = LBound(Tdon)
' If Max = -1 Then Max = UBound(Tdon)
' For R = Min + 1 To Max: Arg = Tdon(R)
' Mn = Min: Mx = R
' Do: S = (Mn + Mx) \ 2
' If Tdon(S) <= Arg Then Mn = S + 1 Else Mx = S
' Q = Q + 1
' Loop Until Mx <= Mn
' For S = R To Mn + 1 Step -1: Tdon(S) = Tdon(S - 1): Q = Q + 1: ch = ch + 1: Next S
' Tdon(S) = Arg
' Next R
' SortDichotomique = Tdon
'End Function
Mais non saucisse j'ai seulement utilisé la function SortDichotomique 🤣 avec mon pré tric'est ça la différence saucisse!!!
Sub TrieDicotomique(Dico As Collection, Value As String, Index As Integer)
Dim Min As Integer, Max As Integer, i As Integer
Select Case Dico.Count
Case 0: Dico.Add Array(Value, Index)
Case 1: If Dico(1)(0) < Value Then Dico.Add Array(Value, Index) Else Dico.Add Array(Value, Index), before:=1
Case Else
Min = 1: Max = Dico.Count
Do While Max <> Min
If Dico(Min)(0) >= Value Then Dico.Add Array(Value, Index), before:=Min: Exit Sub
If Dico(Max)(0) <= Value Then Dico.Add Array(Value, Index), after:=Max: Exit Sub
If Max - Min = 1 Then
If Dico(Min)(0) <= Value And Dico(Max)(0) => Value Then Dico.Add Array(Value, Index), before:=Max: Exit Sub
End If
i = Min + ((Max - Min) / 2)
If Dico(i)(0) < Value Then
Min = i
Else
Max = i
End If
Loop
End Select
End Sub
Sub test()
Dim t(1 To 20000) As String, i As Integer
Randomize Timer
For i = 1 To 20000
t(i) = Chr(64 + (Int((26 * Rnd) + 1)))
Next
Dim Dico As New Collection
For i = 1 To 20000
TrieDicotomique Dico, t(i), i
Next
For i = 1 To 20000
ActiveCell.Offset(i) = Dico(i)(0)
Next
Dim CROISSAN(1 To 20000) As String
For i = 1 To 20000
CROISSAN(i) = t(Dico(i)(1))
Next
Dim Ti As Integer, DECROISSAN(1 To 20000) As String
For i = 20000 To 1 Step -1
Ti = Ti + 1
DECROISSAN(Ti) = t(Dico(i)(1))
Next
End Sub
Dim Q&, Ch&
Sub test_dichotomique()
Q = 0: Ch = 0
Dim Tdon, tim#
Tdon = Application.Transpose([A1:a10].Value)
tim = Timer
Tdon = SortDichotomique(Tdon)
msg = Format(Timer - tim, "#0.00") & " secondes" & vbCrLf & Q & " tours de boucle" & vbCrLf & Ch & " interversions"
Cells(1, 3).Resize(UBound(Tdon)) = Tdon
#If Not Mac Then
Application.Speech.Speak msg, True
#End If
MsgBox msg
End Sub
Function SortDichotomique(Tdon, Optional ByVal Min As Long = -1, Optional ByVal Max As Long = -1)
Dim VPiv, Crs As Long, Dcr As Long, V, R As Long, Arg, Mn As Long, Mx As Long, S As Long
If Min = -1 Then Min = LBound(Tdon)
If Max = -1 Then Max = UBound(Tdon)
For R = Min + 1 To Max: Arg = Tdon(R)
Debug.Print "arg : " & Arg & " index : " & R
Mn = Min: Mx = R
Do: S = (Mn + Mx) \ 2
Debug.Print "portion de :" & Mn & " à : " & Mx
If Tdon(S) <= Arg Then Mn = S + 1 Else Mx = S
Debug.Print "test de l'index du milieu: index :" & S
Q = Q + 1
Loop Until Mx <= Mn
For S = R To Mn + 1 Step -1: Tdon(S) = Tdon(S - 1): Q = Q + 1: Ch = Ch + 1: Next S
Tdon(S) = Arg
Debug.Print Join(Tdon, ",")
Debug.Print "**************************************"
Next R
SortDichotomique = Application.Transpose(Tdon)
End Function
arg : 9 index : 2
portion de :1 à : 2
test de l'index du milieu: index :1
5,9,3,7,1,6,4,8,2,10
**************************************
arg : 3 index : 3
portion de :1 à : 3
test de l'index du milieu: index :2
portion de :1 à : 2
test de l'index du milieu: index :1
3,5,9,7,1,6,4,8,2,10
**************************************
arg : 7 index : 4
portion de :1 à : 4
test de l'index du milieu: index :2
portion de :3 à : 4
test de l'index du milieu: index :3
3,5,7,9,1,6,4,8,2,10
**************************************
arg : 1 index : 5
portion de :1 à : 5
test de l'index du milieu: index :3
portion de :1 à : 3
test de l'index du milieu: index :2
portion de :1 à : 2
test de l'index du milieu: index :1
1,3,5,7,9,6,4,8,2,10
**************************************
arg : 6 index : 6
portion de :1 à : 6
test de l'index du milieu: index :3
portion de :4 à : 6
test de l'index du milieu: index :5
portion de :4 à : 5
test de l'index du milieu: index :4
1,3,5,6,7,9,4,8,2,10
**************************************
arg : 4 index : 7
portion de :1 à : 7
test de l'index du milieu: index :4
portion de :1 à : 4
test de l'index du milieu: index :2
portion de :3 à : 4
test de l'index du milieu: index :3
1,3,4,5,6,7,9,8,2,10
**************************************
arg : 8 index : 8
portion de :1 à : 8
test de l'index du milieu: index :4
portion de :5 à : 8
test de l'index du milieu: index :6
portion de :7 à : 8
test de l'index du milieu: index :7
1,3,4,5,6,7,8,9,2,10
**************************************
arg : 2 index : 9
portion de :1 à : 9
test de l'index du milieu: index :5
portion de :1 à : 5
test de l'index du milieu: index :3
portion de :1 à : 3
test de l'index du milieu: index :2
portion de :1 à : 2
test de l'index du milieu: index :1
1,2,3,4,5,6,7,8,9,10
**************************************
arg : 10 index : 10
portion de :1 à : 10
test de l'index du milieu: index :5
portion de :6 à : 10
test de l'index du milieu: index :8
portion de :9 à : 10
test de l'index du milieu: index :9
1,2,3,4,5,6,7,8,9,10
**************************************
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?
We use cookies and similar technologies for the following purposes:
Est ce que vous acceptez les cookies et ces technologies?