nag_sort_realvec_sort (m01ca) is based on Singleton's implementation of the ‘median-of-three’ Quicksort algorithm (see
Singleton (1969)), but with two additional modifications. First, small subfiles are sorted by an insertion sort on a separate final pass (see
Sedgewick (1978)). Second, if a subfile is partitioned into two very unbalanced subfiles, the larger of them is flagged for special treatment: before it is partitioned, its end points are swapped with two random points within it; this makes the worst case behaviour extremely unlikely.
Singleton R C (1969) An efficient algorithm for sorting with minimal storage: Algorithm 347 Comm. ACM 12 185–187
Not applicable.
This example reads a list of double numbers and sorts them into ascending order.
function m01ca_example
fprintf('m01ca example results\n\n');
rv = [1.3, 5.9, 4.1, 2.3, 0.5, 5.8, 1.3, 6.5, ...
2.3, 0.5, 6.5, 9.9, 2.1, 1.1, 1.2, 8.6];
m1 = int64(1);
order = 'Ascending';
[rv, ifail] = m01ca(rv, m1, order);
fprintf('Sorted numbers:\n\n');
fprintf('%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f%7.1f\n',rv);