The Quicksort Subroutine
Callout C shows the Quicksort subroutine, which requires three parameters: the name of the array to sort and the lower and upper indexes indicating the range of array elements to be sorted. To sort the entire array, the Sort subroutine calls the Quicksort subroutine with a lower index of the first element (i.e., zero) and an upper index of the last element (determined by the UBound function).
Quicksort is a divide-and-conquer sorting algorithm that quickly divides the array at the midpoint, sorts the portions of the array before and after the midpoint, and continues recursively until the entire array is sorted. (You can find a discussion of how the Quicksort algorithm works in most computer science textbooks.)
Comparing Array Elements
To allow for different ordering of array elements, the Quicksort subroutine uses the function reference in the CompareFunc variable to compare array elements. All of the comparison functions require two arguments containing the array items being compared. If the first item is less than the second, the comparison function returns -1; if the items are equal, the function returns 0; and if the first item is greater than the second, the function returns 1. . . .
ibotca April 01, 2006 (Article Rating: