partial_sort
Sorts until the first n elements are correct
Definition
The partial_sort() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class RandomAccessIterator >
void partial_sort(
RandomAccessIterator first,
RandomAccessIterator sortEnd,
RandomAccessIterator last
);
template < class RandomAccessIterator, class BinaryPredicate >
void partial_sort(
RandomAccessIterator first,
RandomAccessIterator sortEnd,
RandomAccessIterator last
BinaryPredicate comp
);Parameters:
| Parameter | Description |
| first | A random-access iterator addressing the position of the first element in the range to be sorted |
| last | A random-access iterator addressing the position one past the final element in the range to be partially sorted |
| sortEnd | A random-access iterator addressing the position one past the final element in the sub-range to be sorted |
| comp | User-defined predicate function object that defines the comparison criterion to be satisfied by successive elements in the ordering. A binary predicate takes two arguments and returns true when satisfied and false when not satisfied |
Description
Partial_sort algorithm partially sorts a range. After calling this function, the elements between first and sortEnd will be sorted and the elements between sortEnd and last will be in an unspecied order.
This function sorts a range of size sortEnd - first by taking its elements between first and last.
The first version compares objects using operator<, and the second compares objects using a function object comp.
Return Value
None.
Complexity
This algorithm performs approximately (last - first) * log(sortEnd - first) comparisons.