Skip to content

Instantly share code, notes, and snippets.

@WangYihang
Created March 8, 2021 01:55
Show Gist options
  • Save WangYihang/d767c1fe630ac5170b1abdb768f53ac4 to your computer and use it in GitHub Desktop.
Save WangYihang/d767c1fe630ac5170b1abdb768f53ac4 to your computer and use it in GitHub Desktop.
#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