// 全排列.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <stdio.h> #include <string> int n = 0; void swap(char *a, char *b) { char m; m = *a; *a = *b; *b = m; } void perm(char list[], int k, int m) { int i; if (k == m) { printf("%s\n", list); n++; } else { for (i = k; i <= m; i++) { swap(&list[k], &list[i]); perm(list, k + 1, m); swap(&list[k], &list[i]); } } } int _tmain(int argc, _TCHAR* argv[]) { int number; char list[]="abce"; number=strlen(list); perm(list, 0, number - 1); printf("\n\tthere are total %d resultants\n", n); system("pause"); return 0; }