I am working on an iteration related issue. I have to pass two ints to a function, which is the number of N objects and M values ββthat all permutations should find. I am also given a sample of what the output should look like.
void perm_iter (int N, int nr_values) and the output to be printed is as follows:
Called : perm_iter(3, 2);
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
I understand the concept of recursion using the swap function to reorder strings to find all permutations of a string, but I'm not sure how to use iteration to get the same or similar result. Is this the case when I need to use the stack and push / pop iteratively to get an answer? I thought I could use something like a set of nested loops to replace recursion and get something like this output, but I'm not sure how to set up loops to go through each permutation, and not just iterations, possible permutations.
Any help would be appreciated and thanks for your time.
source
share