Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

partial_sort_copy()

Module:  Standard C++ Library   Library:  Algorithms


Function

Local Index

No Entries

Summary

Templatized algorithm for sorting collections of entities

Synopsis

#include <algorithm>

namespace std {
  template <class InputIterator,
            class RandomAccessIterator>
  void partial_sort_copy(InputIterator start,
                         InputIterator finish,
                         RandomAccessIterator result_start,
                         RandomAccessIterator result_finish);
  template <class InputIterator,
            class RandomAccessIterator,
            class Compare>
  void partial_sort_copy(InputIterator start,
                         InputIterator finish,
                         RandomAccessIterator result_start,
                         RandomAccessIterator result_finish,
                         Compare comp);
}

Description

The partial_sort_copy() algorithm places the smaller of finish - start and result_finish - result_start sorted elements from the range [start, finish) into the range beginning at result_start (in other words, the range: [result_start, result_start+min(finish - start, result_finish - result_start)). The effect is as if the range [start,finish) were placed in a temporary buffer, sorted, and then as many elements as possible copied into the range [result_start, result_finish).

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_copy() does approximately (finish-start) * log(min(finish-start, result_finish-result_start)) comparisons.

Example

See Also

sort()¸ stable_sort(), partial_sort()

Standards Conformance

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



Previous fileTop of DocumentContentsIndex pageNext file

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.