Lets say I have a vector of integers v = {0, 1,..., N-1} of size N.
Given a size k, I want to generate all k-sized combinations of v.
for example: k = 2, N = 10 {0,1}, {0,2}, ..., {0,9}, {1,2}, ..., {8,9} But I want to do it one by one, using a method called NextCombination:
bool NextCombination(vector<int>& v, int k, int N){ if( is not the last combination){ turn v into it's next combination return true; } return false; } that means, given the current state of v, the size k of the combination and the total number of elements, I'd like to change v (if possible) and return a bool indicating it was possible to get some next combination out of v.
I could not figure out how to make this without some boring recursions, and since this is just small problem of something I'm doing, I would like to figure out some smart/small solution to that.