NAG Library Function Document
nag_double_sort (m01cac) rearranges a vector of real numbers into ascending or descending order.
||nag_double_sort (double vec,
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.
Maclaren N M (1985) Comput. J. 28 448
Sedgewick R (1978) Implementing Quicksort programs Comm. ACM 21 847–857
Singleton R C (1969) An efficient algorithm for sorting with minimal storage: Algorithm 347 Comm. ACM 12 185–187
: elements of vec
must contain real values to be sorted.
On exit: these values are rearranged into sorted order.
: the length of vec
, where is an implementation-dependent value for the maximum size of an array.
On entry: specifies whether the array will be sorted into ascending or descending order.
– NagError *Input/Output
The NAG error argument (see Section 3.7
in How to Use the NAG Library and its Documentation).
Error Indicators and Warnings
On entry, order
had an illegal value.
On entry, .
Constraint: , an implementation-dependent size that is printed in the error message.
On entry, .
Parallelism and Performance
nag_double_sort (m01cac) is not threaded in any implementation.
The average time taken by the function is approximately proportional to . The worst case time is proportional to but this is extremely unlikely to occur.
The example program reads a list of real numbers and sorts them into ascending order.
Program Text (m01cace.c)
Program Data (m01cace.d)
Program Results (m01cace.r)