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

partial_sort()

Library:  Algorithms


Function

Local Index

No Entries

Summary

A generic algorithm for sorting collections of entities

Synopsis

#include <algorithm>

namespace std {
  template <class RandomAccessIterator>
  void partial_sort(RandomAccessIterator start,
                    RandomAccessIterator mid,
                    RandomAccessIterator finish);

  template <class RandomAccessIterator, class Compare>
  void partial_sort(RandomAccessIterator start,
                    RandomAccessIterator mid, 
                    RandomAccessIterator finish, 
                    Compare comp);
}

Description

The partial_sort() algorithm takes the range [start,finish) and sorts the first mid - start values in ascending order. The remaining elements in the range (those in [mid, finish)) are not in any defined order. The first version of the algorithm uses operator<() as the comparison operator for the sort. The second version uses the function object comp.

Complexity

partial_sort() does approximately (finish - start) * log(mid-start) comparisons. This implementation of partial_sort() is implemented using heapsort, which is O(N * log(N)) in the worst case.

Example

See Also

sort(), stable_sort(), partial_sort_copy()

Standards Conformance

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



Previous fileTop of DocumentContentsIndex pageNext file