I have an integer vector of size “n”.
e.g.
std::vector<int> vec;
vec.pushback(0);
vec.pushback(1);
vec.pushback(2);
vec.pushback(3);
....
Now i want to generate all possible combinations of size = {0, 1, 2, … , n}.
please keep in mind that
{0, 1, 3} is not equal to {3, 1, 0} or {1, 0, 3} or {3, 0, 1}
Please help me if you have an idea.
Thanks in advance.
You could do something like this:
As per @JamesKanze’s comment, this can only work if the vector is sorted to begin with, so if you have an unsorted vector, you should call
std::sorton it first.Looking at this, it says:
You can see it in action here