Sub Quicksort (List() As Long, start As Integer, finish As Integer) Dim pivot As Long Dim hi As Integer Dim lo As Integer Dim i As Integer ' If the list has no more than 1 element, it's sorted. If start >= finish Then Exit Sub ' Pick a dividing item. i = Int((finish - start + 1) * Rnd + start) pivot = List(i) ' Swap it to the front so we can find it easily. List(i) = List(start) ' Move the items smaller than this into the left portion of the list. ' Move the others into the right. lo = start hi = finish Do ' Look down from hi for a value < pivot. Do While List(hi) >= pivot hi = hi - 1 If hi <= lo Then Exit Do Loop If hi <= lo Then List(lo) = pivot Exit Do End If ' Swap the lo and hi values. List(lo) = List(hi) ' Look up from lo for a value >= pivot. lo = lo + 1 Do While List(lo) < pivot lo = lo + 1 If lo >= hi Then Exit Do Loop If lo >= hi Then lo = hi List(hi) = pivot Exit Do End If ' Swap the lo and hi values. List(hi) = List(lo) Loop ' Sort the two sublists Quicksort List(), start, lo - 1 Quicksort List(), lo + 1, finish End Sub ''''Listing 3. Quicksort. ''''Link to article about sorting in V.B. ''''
Link to another article about sorting in V.B. ''''
Yet another one about sorting in V.B.
/* ========== Quicksort implementation in Python. (It creates two lists, then combines them.) def QuickSort(myList): if myList == []: return [] # Empty lists are sorted by definition pivot = myList[0] beforePivot = [x for x in myList[1:] if x <= pivot] afterPivot = [x for x in myList if x > pivot] return QuickSort(beforePivot) + [pivot] + QuickSort(afterPivot) */