#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<string> #include<algorithm> #define MAX 1100 using namespace std; int perm1[MAX], perm2[MAX]; bool used[MAX]; void _permutation(int pos, int n){ if (pos == n){ for (int i = 0; i < n; i++) cout << perm2[i] << ","; cout << endl; return; } for (int i = 0; i < n; i++){ if (!used[i]){ perm2[pos] = perm1[i]; used[i] = 1; _permutation(pos + 1, n); used[i] = 0; } } } int main() { int n = 4; for (int i = 0; i < n; i++) perm1[i] = i; memset(used, 0, sizeof(used)); _permutation(0, n); system("pause"); return 0; }