VBScript QuickSort example
Sub QuickSort(avarValues, iavarValuesFirst, iavarValuesLast)
Dim iavarValuesPivot
Dim iavarValuesSwapFirst
Dim iavarValuesSwapLast
Dim varSwap
If iavarValuesLast - iavarValuesFirst = 1 Then
If avarValues(iavarValuesFirst) > avarValues(iavarValuesLast) Then
varSwap = avarValues(iavarValuesFirst)
avarValues(iavarValuesFirst) = avarValues(iavarValuesLast)
avarValues(iavarValuesLast) = varSwap
End If
End If
iavarValuesPivot = avarValues((iavarValuesFirst + iavarValuesLast) \ 2)
avarValues((iavarValuesFirst + iavarValuesLast) \ 2) = avarValues(iavarValuesFirst)
avarValues(iavarValuesFirst) = iavarValuesPivot
iavarValuesSwapFirst = iavarValuesFirst + 1
iavarValuesSwapLast = iavarValuesLast
Do
Do While iavarValuesSwapFirst < iavarValuesSwapLast _
And avarValues(iavarValuesSwapFirst) <= iavarValuesPivot
iavarValuesSwapFirst = iavarValuesSwapFirst + 1
Loop
Do While avarValues(iavarValuesSwapLast) > iavarValuesPivot
iavarValuesSwapLast = iavarValuesSwapLast - 1
Loop
If iavarValuesSwapFirst < iavarValuesSwapLast Then
varSwap = avarValues(iavarValuesSwapFirst)
avarValues(iavarValuesSwapFirst) = avarValues(iavarValuesSwapLast)
avarValues(iavarValuesSwapLast) = varSwap
End If
Loop While iavarValuesSwapFirst < iavarValuesSwapLast
avarValues(iavarValuesFirst) = avarValues(iavarValuesSwapLast)
avarValues(iavarValuesSwapLast) = iavarValuesPivot
If iavarValuesFirst < (iavarValuesSwapLast - 1) Then
Call QuickSort(avarValues, iavarValuesFirst, iavarValuesSwapLast - 1)
End If
If iavarValuesSwapLast + 1 < iavarValuesLast Then
Call QuickSort(avarValues, iavarValuesSwapLast + 1, iavarValuesLast)
End If
End Sub
|