(转载:
http://www.cplusplus.com/reference/algorithm/sort/)
default (1) | template <class RandomAccessIterator> void sort (RandomAccessIterator first, RandomAccessIterator last);custom (2) template <class RandomAccessIterator, class Compare> void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
Sort elements in range
Sorts the elements in the range [first,last) into ascending order.The elements are compared using operator< for the first version, and comp for the second.Equivalent elements are not guaranteed to keep their original relative order (see stable_sort). Parameters
Return valuenoneExample
Output:
ComplexityOn average, linearithmic in the distance between first and last: Performs approximatelyN*log2(N) (where N is this distance) comparisons of elements, and up to that many element swaps (or moves).Data racesThe objects in the range[first,last) are modified.ExceptionsThrows if any of the element comparisons, the element swaps (or moves) or the operations on iterators throws.Note that invalid arguments cause undefined behavior.
下面是一个字符串的例子:
(更多关于<algorithm>请参考<http://www.cplusplus.com/reference/algorithm/) |
---|