Question: Write the code for producing/printing permutations of the characters in a string. For example: If "abc" is the input string, output permutations should be "abc", "bac", "bca", "acb", "cab", "cba".

Solution: The idea here is to put each character in the string in the 1st position and combine it with the permutation of the characters in the rest of the string. As you can see this is also a recursive definition. Pseudo Code:

For i=0 to N
1. Swap letters 0 and i.
2. Permute letters 1 to N-1, printing or saving the entire string each time.

Permute(char* inputStart, char* current)
{
char *swap;
char temp;

if(*(current + 1) = '\0')
printf("%s\n", inputStart);
else
{
for(swap = current; *swap != '\0'; ++swap)
{
temp = *swap;
*swap = *current;
*current = temp;

Permute(inputStart, current + 1);

//revert the letters
*current = *swap;
*swap = temp;
}
}
}