Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Mauro!
Il mio algoritmo preferito :-)
Private Sub WirthQuickSort_test()
Dim a1 As Variant
Dim a2 As Variant
a1 = Array(4, 7, 1, 9, 2)
Debug.Print Join(a1, ",")
a2 = WirthQuickSort(a1)
Debug.Print Join(a2, ",")
End Sub
' Niklaus Wirth
' _Algoritmi + Strutture Dati = Programmi_
' Tecniche Nuove, Milano 1987.
' 2 ORDINAMENTI
' 2.2 Ordinamento di array
' 2.2.6 Ordinamento per partizione
' Versione Visual Basic 6 a cura di:
' Maurizio Borrelli
Public Function WirthQuickSort(ByVal a As Variant) As Variant
Const PLEFT = 0, PRIGHT = 1
Dim c As Long, n As Long, l As Long, r As Long
Dim i As Long, j As Long
Dim v As Variant, d As Variant
c = 1: n = ((UBound(a) - LBound(a)) \ 6) + 1
If n > c Then
ReDim s(PLEFT To PRIGHT, c To n)
Else
ReDim s(PLEFT To PRIGHT, c To c)
End If
s(PLEFT, c) = LBound(a): s(PRIGHT, c) = UBound(a)
Do
l = s(PLEFT, c): r = s(PRIGHT, c): c = c - 1
Do
i = l: j = r: v = a((l + r) \ 2)
Do
Do While a(i) < v
i = i + 1
Loop
Do While v < a(j)
j = j - 1
Loop
If i <= j Then
d = a(i): a(i) = a(j): a(j) = d
i = i + 1: j = j - 1
End If
Loop Until i > j
If (j - l) < (r - i) Then
If i < r Then
c = c + 1
s(PLEFT, c) = i: s(PRIGHT, c) = r
End If
r = j
Else
If (l < j) Then
c = c + 1
s(PLEFT, c) = l: s(PRIGHT, c) = j
End If
l = i
End If
Loop Until l >= r
Loop Until c = 0
WirthQuickSort = a
End Function