SortHeap2DArray (Function)
The SortHeap2DArray function performs a linked heap sort of values in a two dimensional array, using the primary dimension as the key.
Syntax
SortHeap2DArray(PriceArray, Size1, Size2, Order)
Returns (Boolean)
The order of values of the two-dimensional array specified in PriceArray are changed as the result of running SortHeap2DArray. The SortHeap2DArray function itself returns True.
Parameters
Name |
Type |
Description |
MyArray |
Numeric Array |
Specifies the name of a numeric array containing values upon which the sort is performed. |
Size1 |
Numeric |
Sets the number of array elements (size) in the 1st dimension to be sorted. |
Size2 |
Numeric |
Sets the number of array elements (size) in the 2nd dimension to include in the sort. |
Order |
Numeric |
Sets the sort order. 1 = sort descending, -1 = sort ascending |
Remarks
This function is used to change the order of values in an array by sorting them in either ascending or descending order based on the HiLo input. The sort is performed using the elements of the 1st dimension as a key.
As a rule of thumb, consider using this heap sort, SortHeap2DArray, rather than Sort2DArray, when the array to be sorted contains more than 25 elements in its second dimension and speed is the primary concern. Be aware, however, that Sort2DArray and SortHeap2DArray may not return the same sorted array in all cases in which there are identical elements in the first dimension of the array. This is because both sorts are "unstable" sorts.
The value for the Size1 and Size2 input parameters should always be a whole number greater than 0 and is typically equal to the number of data elements in the array.
The SortHeap2DArray function only works with two-dimensional arrays. All array-based referencing begins with array element 1.
Example
Performs an ascending sort of the user declared two-dimensional array..
Array: myArray[30,4](0);
{… (assign values to array) }
Value1 = SortHeap2DArray(myArray, 30, 4, -1);