nag_sort_intvec_sort (m01cb) 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 integers and sorts them into descending order.
function m01cb_example
fprintf('m01cb example results\n\n');
iv = [int64(23) 45 45 67 69 90 999 1 78 112 24 69 96 99 45 78];
m1 = int64(1);
order = 'Descending';
[iv, ifail] = m01cb(iv, m1, order);
fprintf('Sorted numbers:\n\n');
fprintf('%5d%5d%5d%5d%5d%5d%5d%5d\n',iv);