yoo, rein zufällig
Sub Quicksort( array_sort )
Dim start%, ende%, starthelp%, endehelp%, start_ret%, ende_ret%, maxlength%,stackpointer%, pivot%
Dim v_value, v_compare
' Abbruch falls nur 1 Element
If Ubound( array_sort ) < 1 Then Exit Sub
num& = True
For i% = 0 To Ubound(array_sort)
On Error Goto NOT_NUMERIC
tmp& = array_sort(i%)
Next
maxlength% = Ubound( array_sort )
' Stack initialisieren auf maximale Größe
Dim array_start() As Integer, array_ende() As Integer
Redim array_start( maxlength% ) As Integer
Redim array_ende( maxlength% ) As Integer
' Hilfsarray
Dim array_help() As Variant
Redim array_help( maxlength% ) As Variant
' Legt Anfangswerte auf Stack
array_start( 0 ) = Lbound( array_sort )
array_ende( 0 ) = Ubound( array_sort )
' Schleife -> solange Stack belegt ist
Do While stackpointer% >= 0
' Holte Arraybereich von Stack
start% = array_start( stackpointer% )
ende% = array_ende( stackpointer% )
stackpointer% = stackpointer% -1
' Eigentliche Sortierfunktion S T A R T
starthelp% = start%
endehelp% = ende%
' Pivotelement
pivot% = (start% + ende%) / 2
v_compare = array_sort( pivot% )
' Sortieren nach > Pivotelement und < Pivotelement
' Vor Pivotelement
Dim n%
For n% = start% To pivot% -1
v_value = array_sort( n% )
If num& Then
v_compare = Cint(v_compare)
v_value = Cint(v_value)
End If
If ( v_compare > v_value ) Then
array_help( starthelp%) = v_value
starthelp% = starthelp% + 1
Else
array_help( endehelp% ) = v_value
endehelp% = endehelp% -1
End If
Next
' Nach Pivotelement
For n% = ende% To pivot%+1 Step -1
v_value = array_sort( n% )
If num& Then
v_compare = Cint(v_compare)
v_value = Cint(v_value)
End If
If ( v_compare > v_value ) Then
array_help( starthelp%) = v_value
starthelp% = starthelp% + 1
Else
array_help( endehelp% ) = v_value
endehelp% = endehelp% -1
End If
Next
' Pivotelement wird zurück in Liste gelegt
array_help( starthelp% ) = v_compare
' Werte aus Hilfsarray werden zurückgeschrieben
For n% = start% To ende%
array_sort( n% ) = array_help( n% )
Next
' Sortierbereiche neu festlegen
start_ret% = endehelp% + 1
ende_ret% = ende%
start% = start%
ende% = starthelp% - 1
' Legt 1 Arraybereich auf Stack
If start% < ende% Then
stackpointer% = stackpointer% + 1
array_start( stackpointer% ) = start%
array_ende( stackpointer% ) = ende%
End If
' Legt 2 Arraybereich auf Stack
If start_ret% < ende_ret% Then
stackpointer% = stackpointer% + 1
array_start( stackpointer% ) = start_ret%
array_ende( stackpointer% ) = ende_ret%
End If
Loop
Exit Sub
NOT_NUMERIC:
num& = False
Resume Next
End Sub