Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

sort()

Library:  Algorithms


Function

Local Index

No Entries

Summary

A templatized algorithm for sorting collections of entities

Synopsis

#include <algorithm>

namespace std {
  template <class RandomAccessIterator>
  void sort(RandomAccessIterator start, 
            RandomAccessIterator finish);
  template <class RandomAccessIterator, class Compare>
  void sort(RandomAccessIterator start, 
            RandomAccessIterator finish, Compare comp);
}

Description

The sort() algorithm sorts the elements in the range [start, finish) in ascending order using either operator<() or the function object comp. The algorithm is not stable; that is, it does not preserve the order of elements that are equivalent (i.e., those for which (a < b && b < a) == false). If maintaining such an ordering is is important, stable_sort() should be used instead. sort() is implemented using introsort.

Complexity

sort() performs approximately N * log(N) comparisons in the worst case, where N equals finish - start.

Example

See Also

stable_sort(), partial_sort(), partial_sort_copy()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.3.1.1



Previous fileTop of DocumentContentsIndex pageNext file