Single Dimension Sort with Single Compare -- either 0 or 1 based:   Return to List

' To call the QuickSort routine, you would use a statement such as:
Quick_Sort aryTemp(), 1, UBound(aryTemp()) ' Sorts extremely fast !!

Private Sub Quick_Sort(ByRef SortArray As Variant, ByVal First As Long, ByVal Last As Long)
Dim Low As Long, High As Long
Dim Temp As Variant, List_Separator As Variant
Low = First
High = Last
List_Separator = SortArray((First + Last) / 2)
Do
    Do While (SortArray(Low) < List_Separator)
        Low = Low + 1
    Loop
    Do While (SortArray(High) > List_Separator)
        High = High - 1
    Loop
    If (Low <= High) Then
        Temp = SortArray(Low)
        SortArray(Low) = SortArray(High)
        SortArray(High) = Temp
        Low = Low + 1
        High = High - 1
    End If
Loop While (Low <= High)
If (First < High) Then Quick_Sort SortArray, First, High
If (Low < Last) Then Quick_Sort SortArray, Low, Last
End Sub

See also:
Array Converted to Delimited Text String
Building an Array of Filenames (after browse)
Delimited Text to an Array (similar to Split())
Determining Upper & Lower Array Bounds
Erasing an Array (removing all the elements)
Feed an Array into a New Document (del dupes)
Filename Array from Active Directory
QuickSort routine
QuickSort (Fast!!) (Multidimensional on 2 dims)
QuickSort (Fast!!) (Multidimensional on 3 dims)
Removing Duplicates from an Array
SQL Query Results placed in an Array
Using Split() function to create Array



Note to Webmaster