]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | Copyright 2010 Neil Groves | |
3 | Distributed under the Boost Software License, Version 1.0. | |
4 | (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | /] | |
6 | [section:stable_sort stable_sort] | |
7 | ||
8 | [heading Prototype] | |
9 | ||
10 | `` | |
11 | template<class RandomAccessRange> | |
12 | RandomAccessRange& stable_sort(RandomAccessRange& rng); | |
13 | ||
14 | template<class RandomAccessRange> | |
15 | const RandomAccessRange& stable_sort(const RandomAccessRange& rng); | |
16 | ||
17 | template<class RandomAccessRange, class BinaryPredicate> | |
18 | RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate pred); | |
19 | ||
20 | template<class RandomAccessRange, class BinaryPredicate> | |
21 | const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate pred); | |
22 | `` | |
23 | ||
24 | [heading Description] | |
25 | ||
26 | `stable_sort` sorts the elements in `rng` into ascending order. `stable_sort` is guaranteed to be stable. The order is preserved for equivalent elements. | |
27 | ||
28 | For versions of the `stable_sort` function without a predicate ascending order is defined by `operator<()` such that for all adjacent elements `[x,y]`, `y < x == false`. | |
29 | ||
30 | For versions of the `stable_sort` function with a predicate, ascending order is designed by `pred` such that for all adjacent elements `[x,y]`, `pred(y,x) == false`. | |
31 | ||
32 | [heading Definition] | |
33 | ||
34 | Defined in the header file `boost/range/algorithm/stable_sort.hpp` | |
35 | ||
36 | [heading Requirements] | |
37 | ||
38 | [*For versions of stable_sort without a predicate] | |
39 | ||
40 | * `RandomAccessRange` is a model of the __random_access_range__ Concept. | |
41 | * `RandomAccessRange` is mutable. | |
42 | * `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. | |
43 | * The ordering relation on `RandomAccessRange`'s value type is a [*strict weak ordering], as defined in the `LessThanComparableConcept` requirements. | |
44 | ||
45 | [*For versions of stable_sort with a predicate:] | |
46 | ||
47 | * `RandomAccessRange` is a model of the __random_access_range__ Concept. | |
48 | * `RandomAccessRange` is mutable. | |
49 | * `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. | |
50 | * `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. | |
51 | ||
52 | [heading Complexity] | |
53 | ||
54 | Best case: `O(N)` where `N` is `distance(rng)`. | |
55 | Worst case: `O(N log(N)^2)` comparisons, where `N` is `distance(rng)`. | |
56 | ||
57 | [endsect] | |
58 | ||
59 |