1 /*************************************************************************
2 > File Name: 26_StringPermutation.cpp
3 > Author: Juntaran
4 > Mail: JuntaranMail@gmail.com
5 > Created Time: 2016年08月31日 星期三 16时11分13秒
6 ************************************************************************/
7
8 #include <stdio.h>
9
10 void Permutation(char* str, char* begin)
11 {
12 if (*begin == '\0')
13 printf("%s\n", str);
14 else
15 {
16 for (char* left = begin; *left != '\0'; left++)
17 {
18 // left与begin交换值
19 char temp = *left;
20 *left = *begin;
21 *begin = temp;
22
23 Permutation(str, begin+1);
24
25 temp = *left;
26 *left = *begin;
27 *begin =temp;
28 }
29 }
30 }
31
32 // 字符串的全排列
33 void Permutation(char* str)
34 {
35 if (str == NULL)
36 return;
37 Permutation(str, str);
38 }
39
40 int main()
41 {
42 char str[] = "abc";
43 Permutation(str);
44
45 return 0;
46 }