Created
November 30, 2012 10:22
-
-
Save radum/4174994 to your computer and use it in GitHub Desktop.
VB QuickSort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'! Sort an array of integers ASC | |
! @author: radum | |
! @version: v0.1 | |
! Description: Sort an array using this example: QuickSort(arr, 0, arr.Len()-1) | |
! arr is the array, 0 is the lower start point and 3rd param is the high end point | |
! if you want to sort only a portion of the array starting from inLow to inHi | |
!' | |
Sub QuickSort(vArray[], inLow, inHi) | |
Dim pivot, tmpSwap, tmpLow, tmpHi | |
tmpLow = inLow | |
tmpHi = inHi | |
pivot = vArray[(inLow + inHi) / 2] | |
While (tmpLow <= tmpHi) | |
'While (vArray[tmpLow] > pivot And tmpLow < inHi) 'Desc | |
While (vArray[tmpLow] < pivot And tmpLow < inHi) 'Asc | |
tmpLow = tmpLow + 1 | |
End While | |
'While (pivot > vArray[tmpHi] And tmpHi > inLow) 'Desc | |
While (pivot < vArray[tmpHi] And tmpHi > inLow) 'Asc | |
tmpHi = tmpHi - 1 | |
end while | |
If (tmpLow <= tmpHi) Then | |
tmpSwap = vArray[tmpLow] | |
vArray[tmpLow] = vArray[tmpHi] | |
vArray[tmpHi] = tmpSwap | |
tmpLow = tmpLow + 1 | |
tmpHi = tmpHi - 1 | |
End If | |
end while | |
If (inLow < tmpHi) Then QuickSort(vArray, inLow, tmpHi) | |
If (tmpLow < inHi) Then QuickSort(vArray, tmpLow, inHi) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment