![]() |
VOOZH | about |
Template RandomAccessIterator partial_sort_copy (InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last); first: Input iterator to the first element in the container. last: Input iterator to the last element in the container. result_first: Random-Access iterator pointing to the initial position in the destination container. result_last: Random-Access iterator pointing to the final position in the destination container. Return Value: It returns an iterator pointing to the element that follows the last element written in the result sequence.Output:
1 1 3Here, since, we declared v1 to be of size 3, so only three elements were stored in it.
Template RandomAccessIterator partial_sort_copy (InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); Here, first, last, result_first and result_last are the same as previous case. comp: Binary function that accepts two elements in the range as arguments, and returns a value convertible to bool. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines. The function shall not modify any of its arguments. This can either be a function pointer or a function object. Return Value: It returns an iterator pointing to the element that follows the last element written in the result sequence.Output:
1 1 3 3 3 7 7
Where to use it ?
v = 100 45 78 23 220 v1 = 23 45 78 100 220So, here v remained the same, and its sorted form is stored into v1.