In the first version, taking no parameters, the comparisons are performed using the operator< between the elements being compared.
In the second version, the comparisons are perfomed using function comp, which performs weak strict ordering (this basically means the comparison operation has to be transitive and irreflexive).
The entire operation does not involve the construction or destruction of any element object.
Parameters
- comp
- Comparison function that, taking two values of the same type than those contained in the list object, returns true if the first argument goes before the second argument in the specific order (i.e., if the first is less than the second), and false otherwise.
Return value
noneExample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
Output:
mylist contains: Three one two mylist contains: one Three two |
For default strings, the comparison is a strict character code comparison, where all uppercase letters compare lower than all lowercase letters, putting all strings beginning by an uppercase letter before in the first sorting operation.
Using the function compare_nocase the comparison is made case insensitive.
Complexity
Approximately NlogN where N is the list size.See also
| list::merge | Merge sorted lists (public member function) |
| list::reverse | Reverse the order of elements (public member function) |
| list::unique | Remove duplicate values (member function) |
