naginterfaces.library.sort.intvec_​sort

naginterfaces.library.sort.intvec_sort(iv, m1, order)[source]

intvec_sort rearranges a vector of integer numbers into ascending or descending order.

For full information please refer to the NAG Library document for m01cb

https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/m01/m01cbf.html

Parameters
ivint, array-like, shape

Elements to of must contain integer values to be sorted.

m1int

Note: this argument represents an array index; the value you supply must be base-1 for compatibility with the NAG Engine.

The index of the first element of to be sorted.

orderstr, length 1

If , the values will be sorted into ascending (i.e., nondecreasing) order.

If , into descending order.

Returns
ivint, ndarray, shape

These values are rearranged into sorted order.

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, has an illegal value: .

Notes

No equivalent traditional C interface for this routine exists in the NAG Library.

intvec_sort 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.

References

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