8.全排列
1 #include <stdlib.h> 2 #include <stdio.h> 3 4 //需要排序的数组 5 char str[10] = "123"; 6 7 //交换两个数据 8 void swap(char *p1, char *p2) 9 { 10 char tmp = *p1; 11 *p1 = *p2; 12 *p2 = tmp; 13 } 14 15 //全排列 16 void pailie(char *pstart) 17 { 18 if (*pstart == '\0') 19 { 20 puts(str); 21 } 22 else 23 { 24 for (char *p = pstart; *p != '\0'; p++) 25 { 26 swap(pstart, p); 27 pailie(pstart + 1); 28 swap(pstart, p); 29 } 30 } 31 } 32 33 //主函数 34 void main() 35 { 36 pailie(str); 37 38 system("pause"); 39 }