Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

14.3 Partial Sort

The generic algorithm partial_sort() sorts only a portion of a sequence. In the first version of the algorithm, three iterators are used to describe the beginning, middle, and end of a sequence. If n represents the number of elements between the start and middle, then the smallest n elements are moved into this range in order. The remaining elements are moved into the second region. The order of the elements in this second region is undefined.

A second version of the algorithm leaves the input unchanged. The output area is described by a pair of random access iterators. If n represents the size of this area, the smallest n elements in the input are moved into the output in order. If n is larger than the input, the entire input is sorted and placed in the first n locations in the output. In either case, the end of the output sequence is returned as the result of the operation.

Because the input to this version of the algorithm is specified only as a pair of input iterators, the partial_sort_copy() algorithm can be used with any of the containers in the Standard C++ Library. In the example program, it is used with a list:


Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998