[The function's declaration. Example]
Sort is an overloaded name; there are actually two sort functions.
template <class RandomAccessIterator>
void sort(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class StrictWeakOrdering>
void sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp);
[A summary of what the function does. Example:]
Sort sorts the elements in [first, last) into ascending order, meaning that if i and j are any two valid iterators in [first, last) such that i precedes j, then *j is not less than *i.
The two versions of sort differ in how they define whether one
element is less than another. The first version compares objects using
operator<
, and the second compares objects using a
function object comp
.
[This section lists the requirements that must be satisfied by the function's template parameters. If the function has no template parameters, this section can be skipped. Example:]
Type  Requirements  

RandomAccessIterator 
 
StrictWeakOrdering 
 
RandomAccessIterator::value_type 

[Functions usually aren't guaranteed to yield a welldefined result for any possible input, but only for valid input; it is an error to call a function with invalid input. This section describes the conditions for validity. Example:]
[first , last) is a valid
range. 
[Example:]
O(N log(N)) comparisons (both average and worstcase), where N is last  first. [2]
[A code fragment that illustrates how to use the function.]
#include <algorithm>
int A[] = {1, 4, 2, 8, 5, 7};
const int N = sizeof(A) / sizeof(int);
sort(A, A + N);
copy(A, A + N, ostream_iterator<int>(cout, " "));
// The output is " 1 2 4 5 7 8"
Comment on This Page
You must be logged in to post a comment.