Skip to content

Instantly share code, notes, and snippets.

@rajivseelam
Created October 16, 2012 08:41
Show Gist options
  • Save rajivseelam/3898081 to your computer and use it in GitHub Desktop.
Save rajivseelam/3898081 to your computer and use it in GitHub Desktop.
Permutations of a String
#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