• The first form sorts the elements in the range [beg,end) with operator <, so range [beg,sortEnd)
contains the elements in sorted order.
• The second form sorts the elements by using the binary predicate
op(elem1,elem2)
as the sorting criterion, so range [beg,sortEnd) contains the elements in sorted order.
• Note that op has to define a strict weak ordering for the values (see Section 7.7, page 314, for
details).
• Note that op should not change its state during a function call. See Section 10.1.4, page 483, for
details.
• Unlike sort(), partial_sort() does not sort all elements but stops the sorting once the first
elements up to sortEnd are sorted correctly. Thus, if, after sorting a sequence, you need only the
first three elements, this algorithm saves time because it does not sort the remaining elements
unnecessarily.
• If sortEnd is equal to end, partial_sort() sorts the full sequence. It has worse performance
than sort() on average but better performance in the worst case. See the discussion about
sorting algorithms in Section 11.2.2, page 511.
• Complexity: between linear and n-log-n (approximately numElems*log(numSortedElems) comparisons).
The following program demonstrates how to use partial_sort():
การแปล กรุณารอสักครู่..