I have been searching for a source code for generating combinations using C++. I found some advanced codes for this but that is good for only specific number predefined data. Can anyone give me some hints, or perhaps, some ideas to generate a combination?
As an example, suppose the set S = { 1, 2, 3, ...., n}
and we pick r= 2
out of it. The input would be n
and r
. In this case, the program will generate arrays of length two. So input of 5 2
would output 1 2, 1 3
.
I had difficulty in constructing the algorithm. It took me a month to think about this.