Created
October 16, 2012 08:41
-
-
Save rajivseelam/3898081 to your computer and use it in GitHub Desktop.
Permutations of a String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void swap(char **s, int low, int high){ | |
char temp; | |
temp = (*s)[low]; | |
(*s)[low] = (*s)[high]; | |
(*s)[high] = temp; | |
// printf("%s\n",*s); | |
} | |
int permute(char *s, int low, int high){ | |
int i; | |
if(low == high){ | |
printf("%s\n",s); | |
} | |
for(i = low; i <= high; i++){ | |
swap(&s,low,i); | |
permute(s,low+1,high); | |
swap(&s,low,i); | |
} | |
return 0; | |
} | |
int main(){ | |
char s[] = "abc"; | |
permute(s, 0, 2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment