Skip to content

Instantly share code, notes, and snippets.

@radum
Created November 30, 2012 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radum/4174994 to your computer and use it in GitHub Desktop.
Save radum/4174994 to your computer and use it in GitHub Desktop.
VB QuickSort
'! 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