I have an array with a bunch of values (the length of the array can vary):
int a[] = {1, 6, 9, 4, 3, 7, 5};
I want to generate all possible combinations available. The problem is that the size of the subset may vary. The user may for instance say he wants all possible combinations with 3 elements. Another user may want a combination with 5 elements. For instance, the skeleton of the function may look like:
combination* getSubsets ( int numberOfElementsInSubset){
.........
}
Where combination might be a class/structure to hold a certain subset. A 2dimensionel array could also be used.
Since the size varies, a bunch of inner loops cannot be hard coded. I have thought of a recursive function that may solve the problem, but can't find a way to start.
Any help will be greatly appreciated.