Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

stable_sort


Algorithm

Summary

A 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 stable_sort (RandomAccessIterator first, 
                  RandomAccessIterator last);

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

Description

The stable_sort algorithm sorts the elements in the range [first, last). The first version of the algorithm uses less than (<) as the comparison operator for the sort. The second version uses the comparison function comp.

The stable_sort algorithm is considered stable because the relative order of the equal elements is preserved.

Complexity

stable_sort does at most N(logN)2 comparisons, where N equals last - first. If enough extra memory is available, it does at most NlogN.

Example

Program Output

Warnings

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

vector<int, allocator>

instead of:

vector<int>

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

See Also

sort,partial_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