Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

partial_sort_copy


Algorithm

Summary

Templatized algorithm for sorting collections of entities.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class InputIterator,
          class RandomAccessIterator>
 void partial_sort_copy (InputIterator first,
                         InputIterator last,
                         RandomAccessIterator result_first,
                         RandomAccessIterator result_last);
template <class InputIterator,
          class RandomAccessIterator,
          class Compare>
 void partial_sort_copy (InputIterator first,
                         InputIterator last,
                         RandomAccessIterator result_first,
                         RandomAccessIterator result_last,
                         Compare comp);

Description

The partial_sort_copy algorithm places the smaller of last - first and result_last - result_first sorted elements from the range [first, last) into the range beginning at result_first (in other words, the range: [result_first, result_first+min(last - first, result_last - result_first)). The effect is as if the range [first,last) were placed in a temporary buffer, sorted, and then as many elements as possible copied into the range [result_first, result_last).

The first version of the algorithm uses less than (operator<) as the comparison operator for the sort. The second version uses the comparison function comp.

Complexity

partial_sort_copy does approximately (last-first) * log(min(last-first, result_last-result_first)) comparisons.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you need to always include the Allocator template argument. For instance, you need to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

sort stable_sort, partial_sort



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998