Hey guys,
I have this doubt for a while
I'd like to know how i find the n smallest number of a set of number and not the smallest number.
For example:
I have this number in the enter: 54621
So, i'd like to know the three smallest number
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
constint n = 3;
std::vector<int> v = {5, 4, 6, 2, 1};
std::partial_sort(v.begin(), v.begin() + n, v.end());
auto begin = v.begin();
auto end = v.begin() + n;
for (auto it = begin; it != end; ++it)
{
std::cout << *it << std::endl;
}
}