Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

partial_sort


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 RandomAccessIterator>
 void partial_sort (RandomAccessIterator first,
                    RandomAccessIterator middle,
                    RandomAccessIterator last);

template <class RandomAccessIterator, class Compare>
 void partial_sort (RandomAccessIterator first,
                    RandomAccessIterator middle, 
                    RandomAccessIterator last, 
                    Compare comp);

Description

The partial_sort algorithm takes the range [first,last) and places the first middle - first values into sorted order. The result is that the range [first, middle) is sorted like it would be if the entire range [first,last) were sorted. The remaining elements in the range (those in [middle, last)) are not in any defined order. 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 does approximately (last - first) * log(middle-first) comparisons.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to 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_copy



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