Created
June 1, 2017 05:27
-
-
Save jxcodetw/bb9c4d5f9d62f6b4d6a4e4a1492da718 to your computer and use it in GitHub Desktop.
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> | |
#include <string.h> | |
void swap(char* a, char* b) { | |
char t = *a; | |
*a = *b; | |
*b = t; | |
} | |
void perm(char* head, int i, int n) { | |
int j; | |
if (i+1 == n) { | |
puts(head); | |
} else { | |
for(j=i;j<n;++j) { | |
swap(head+i, head+j); | |
perm(head, i+1, n); | |
swap(head+i, head+j); | |
} | |
} | |
} | |
char buf[] = "abc"; | |
int main(int argc, char* argv[]) { | |
perm(buf, 0, strlen(buf)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment