- #include <iostream>
- #include <string.h>
- void swap(char* a, char* b)
- {
- char tmp = *a;
- *a = *b;
- *b = tmp;
- }
- void permutation(char* a, int i, int j)
- {
- if ( i == j)
- std::cout << a << '\\n';
- else
- {
- for(int m = i; m < j; ++m)
- {
- swap(a+i, a+m);
- permutation( a, i+1, j);
- swap(a+i, a+m);
- }
- }
- }
- int main()
- {
- char test[100];
- strcpy(test, "abc");
- permutation(test, 0, strlen(test));
- }
- //该片段来自于http://www.codesnippet.cn/detail/021220137656.html
来源: http://www.codesnippet.cn/detail/021220137656.html