Say n single digits in an array of length n . Then the task of generating permutations is reduced to:
- Select one of the digits
n as the first digit to print. A. - Transfer the remaining
n-1 digits.
Recursion.
The pseudocode for such a recursive permute function permute be something like this:
List permute (Array digits) { List permutations = for (i=0; i<n; i++) { firstDigit = digit[i]; Array otherDigits = List subPermutations = permute(otherDigits); } return permutations; }
Then just call permute and print the list, or do something else with it.
EDIT: you also need to process the edge with a 1-digit permute edge.
I think this is already too much information for "homework" :)
Arjunshankar
source share