Tips Tricks Samples

QuickSort routine in LotusScript

There are huge numbers of functions for sorting arrays, this is particularly good for large lists. It is generally easiest to use a bubble sort for lists of less than 10 elements.
Sub QuickSort(vList As Variant, iLow As Integer, iHigh As Integer)
  'Local variables
  Dim vPivot As Variant
  Dim tmpSwap As Variant
  Dim tmpLow As Integer
  Dim tmpHigh As Integer

  tmpLow = iLow
  tmpHigh = iHigh

  vPivot = vList((tmpLow + tmpHigh) / 2)

  While tmpLow < tmpHigh
    While vList(tmpLow) < vPivot And tmpLow < iHigh
      tmpLow = tmpLow + 1
    While vPivot < vList(tmpHigh) And tmpHigh > iLow
      tmpHigh = tmpHigh - 1
    If tmpLow <= tmpHigh Then
      tmpSwap = vList(tmpLow)
      vList(tmpLow) = vList(tmpHigh)
      vList(tmpHigh) = tmpSwap
      tmpLow = tmpLow + 1
      tmpHigh = tmpHigh - 1
    End If
  If iLow < tmphigh Then
    QuickSort vList, iLow, tmpHigh
  End If
  If tmpLow < iHigh Then
    QuickSort vList, tmpLow, iHigh
  End If
End Sub