I need to sort the elements in a std::vector
, but I'm only interested in the top N
items being sorted, not the entire list:
E.g. in a list of 10 elements, only first 3 have to be sorted. Don't care about the rest...
1,2,3,6,7,4,9,8,5
Can this be done using std::sort
?
Edit
I simply needed to find the top N
items in a vector. std::partial_sort_copy
was exactely what I needed.
Try std::partial_sort
instead of std::sort
. :)
This is what std::partial_sort
is for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With