VBnet™ Applying and Understanding the QuickSort

Option Explicit
Public Sub QuickSortVariants(vArray As Variant, inLow As Long, inHi As Long)

   Dim pivot   As Variant
   Dim tmpSwap As Variant
   Dim tmpLow  As Long
   Dim tmpHi   As Long

   tmpLow = inLow
   tmpHi = inHi

   pivot = vArray((inLow + inHi) \ 2)

   While (tmpLow <= tmpHi)

      While (vArray(tmpLow) < pivot And tmpLow < inHi)
         tmpLow = tmpLow + 1

      While (pivot < vArray(tmpHi) And tmpHi > inLow)
         tmpHi = tmpHi - 1

      If (tmpLow <= tmpHi) Then
         tmpSwap = vArray(tmpLow)
         vArray(tmpLow) = vArray(tmpHi)
         vArray(tmpHi) = tmpSwap
         tmpLow = tmpLow + 1
         tmpHi = tmpHi - 1
      End If


   If (inLow < tmpHi) Then QuickSortVariants vArray, inLow, tmpHi
   If (tmpLow < inHi) Then QuickSortVariants vArray, tmpLow, inHi

End Sub



This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s