stable_sort [C++ Reference]
Keywords: stl,algorithm,stable_sort
Date: 2009-10-09T01:44:59-0700

[[stable_sort]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## stable_sort

Syntax:

        #include <algorithm>
        void stable_sort( random_iterator start, random_iterator end );
        void stable_sort( random_iterator start, random_iterator end, StrictWeakOrdering cmp );

The stable_sort() algorithm is like the sort() algorithm, in that it sorts a range of elements into ascending order. Unlike sort(), however, stable_sort() will preserve the original ordering of elements that are equal to each other.

This functionality comes at a small cost, however, as stable_sort() takes a few more comparisons that sort() in the worst case: N (log N)^2 instead of N log N.

Related Topics: binary_search, is_sorted, partial_sort, partial_sort_copy, sort

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •