Skip to content

Instantly share code, notes, and snippets.

@aruslan
Created February 9, 2012 23:45
Show Gist options
  • Save aruslan/1784387 to your computer and use it in GitHub Desktop.
Save aruslan/1784387 to your computer and use it in GitHub Desktop.
/* Function to print permutations of string
This function takes three parameters:
1. String
2. Starting index of the string
3. Ending index of the string. */
void permute(char *a, int i, int n)
{
int j;
if (i == n)
printf("%s\n", a);
else
{
for (j = i; j <= n; j++)
{
swap((a+i), (a+j));
permute(a, i+1, n);
swap((a+i), (a+j)); //backtrack
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment