cpp/algorithm/partial sort

Rearranges elements such that the range contains the sorted  smallest elements in the range.

The order of equal elements is not guaranteed to be preserved. The order of the remaining elements in the range is unspecified.

@1@ Elements are compared using. @3@ Elements are compared using the given binary comparison function. @2,4@ Same as, but executed according to.

Return value
(none)

Complexity
Approximately $(last-first)log(middle-first)$ applications of.

Algorithm
The algorithm used is typically heap select to select the smallest elements, and heap sort to sort the selected elements in the heap in ascending order.

To select elements, a heap is used (see ). For example, for as comparison function, max-heap is used to select  smallest elements.

is used after selection to sort selected elements (see std).

Intended use
algorithms are intended to be used for small constant numbers of selected elements.

Possible implementation
See also the implementations in libstdc++ and libc++.