Created
March 8, 2021 01:55
-
-
Save WangYihang/d767c1fe630ac5170b1abdb768f53ac4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, int left, int right) { | |
char t = a[left]; | |
a[left] = a[right]; | |
a[right] = t; | |
} | |
void permuation(char* a, int left, int right) { | |
if (right == left) { | |
printf("%s\n", a); | |
} else { | |
for (int i = left; i < right; i++) { | |
swap(a, left, i); | |
permuation(a, left + 1, right); | |
swap(a, left, i); | |
} | |
} | |
} | |
int main() { | |
char a[] = "abc"; | |
permuation(a, 0, strlen(a)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment