VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Quick Sort

by M Abdul Samad (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 9th June 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Quick Sort

API Declarations


' Just copy paste the code in your application. The following function will
'sort The array passed as argument e.g QuickSort Array

Rate Quick Sort



Sub QuickSort(Value(), Optional iFrom = -1, Optional iTo = -1)
 
    Dim N As Integer
    If iFrom = -1 Then iFrom = 0
    If iTo = -1 Then iTo = UBound(Value) - 1
    Dim L As Integer, R As Integer
    L = iFrom
    R = iTo
    If Abs(L - R) < 1 Or L >= R Then Exit Sub
    Do While (Abs(L - R) >= 1)
        For I = iFrom + 1 To iTo
            If Value(L) <= Value(R) Then
                L = L + 1
                Swap Value(L), Value(R)
                Exit For
            End If
        Next
        For I = iFrom + 1 To iTo
            If (Value(L) < Value(R)) Then
                R = R - 1
            Else
                Swap Value(L), Value(R)
                Exit For
            End If
        Next
    Loop
    QuickSort Value, iFrom, L - 1
    QuickSort Value, L + 1, iTo
    
End Sub

Sub Swap(ByRef A, ByRef B)
    
    Dim Temp
    Temp = A
    A = B
    B = Temp
   
End Sub


Download this snippet    Add to My Saved Code

Quick Sort Comments

No comments have been posted about Quick Sort. Why not be the first to post a comment about Quick Sort.

Post your comment

Subject:
Message:
0/1000 characters