partial_sort(), partial_sort_copy()

partial_sort() accepts three parameters — first, middle, and last — and an optional fourth parameter that provides an alternative ordering operation. The iterators first and middle mark the range of slots available to place the sorted elements of the container (middle is 1 past the last valid slot). The elements stored beginning at middle through last are unsorted. For example, given the array

int ia[] = {29,23,20,22,17,15,26,51,19,12,35,40 }; 

an invocation of partial_sort() marking the sixth element as middle

partial_sort( ia, ia+5, ia+12 ); 

yields the sequence in which the five smallest elements are sorted:

{ 12,15,17,19,20,29,23,22,26,51,35,40 } 

The elements from middle through last-1 are not placed ...

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.