- Jimmy Page and Robert Plant
QuickSort<>
The SortHandler<T> data type represents a method reference specific to a handler for a QuickSort<> comparison method. SortHandler<T> is defined as follows:
public type<int method<T,T,Base>> SortHandler<T>
Given this definition, the method handler for sort comparison must be defined with the following signature (name can be anything). T is a placeholder for the actual class that was used in that particular implementation of the template.
public method<int> MySortCompareMethod(T Object1, T Object2, Base ExtraObject) { }.
QuickSort<> Methods
QuickSort() | Constructor for the QuickSort<> class |
Sort() | Initiates the sorting process for the specified array |
Compare() | Virtual method to compare two items and return the result |
SetCompareHandler() | Sets the method to be used as a comparison handler during the sort operation |
Derived Classes
None
See Also
Class Hierarchy, Array Methods
public method QuickSort(T[ ] SortArray)
Parameters
SortArray
One dimensional array to be sorted, with data type specified in creation of the template class
Return Value
None
Description
Constructor for the QuickSort<> class. The array containing the data to be sorted is passed in and must not be null.
QuickSort<> Class
public virtual method Sort(Base ExtraObject = null, int LowLimit = 1, int HighLimit = 0)
Parameters
ExtraObject
Script/application specific object to be passed into the comparison method (default is null)
LowLimit
Low limit of the array index to be used in sort operation (one based, default is 1)
HighLimit
High limit of the array index to be used in sort operation (one based, default is 0, which means no upper limit)
Return Value
None
Description
This method performs the sort operation using the array passed into the constructor. The internal sort algorithm will repeatedly call a compare handler, comparing two items at a time, until the entire array (or subset) is sorted. The compare handler is either an internal method, a user specified method, or an override of the Compare() method. Refer to the discussion at the top of this page for more details.
A subset of the array can be sorted, leaving all data outside of the specified sort range intact and unchanged. Both limits are one based array indices to specify how much of the array to sort. If the high limit of the array is greater than zero, that will be the highest index of the array to be sorted. If the high limit is zero (default), there is no limit on the upper end, so the sort operation will go from the low limit to the end of the array.
QuickSort<> Class
public method<int> unique virtual Compare(T Object1, T Object2, Base ExtraObject)
Parameters
Object1
Reference to first object to be compared
Object2
Reference to second object to be compared
ExtraObject
Reference to script/application specific object passed into constructor
Return Value
Result of the comparison: -1, 0 or 1
Description
This method compares the two items passed into the method and returns the result of the comparison. If Item1 is less then Item2, it returns -1. If they are equal, it returns 0, and if Item1 is greater than Item2, it returns 1.
This is the default implementation of the comparison handler, and the logic contained here will only be used if the user has not registed a comparison handler (SetCompareHandler()) and the user has not overridden the Compare method in a derived class. Refer to the description at the top of this page for default comparison logic.
QuickSort<> Class
public method SetCompareHandler(SortHandler<T> ComparisonMethod)
Parameters
ComparisonMethod
Method reference for the comparison method
Return Value
None
Description
This method sets a script/application specific method to perform the comparison for the sorting process. When the Sort() method is called, this sort handler method will then be called repeatedly in order to compare two items. This handler method does not need to know anything about the overall sorting algorithm. This method simply needs to perform a comparison between two of the items that are contained in the array and return the result. The result of the comparison is used by the internal sorting algorithm to determine whether more comparisons are needed or the entire array (or subset of the array) is sorted.
As described at the top of this page, the comparison method must conform to the following syntax (name is arbitrary).
public method<int> MySortCompareMethod(T Object1, T Object2, Base ExtraObject) { }
QuickSort<> Class