public class PermutCombi {
public static void output(int[] num, int[] arr) {
int i;
for (i = arr.length - 1; i >= 0; --i)
System.out.print((arr[num[i]]) + " ");
System.out.println();
}
public static void permutCombi(int[] arr, int n) {
int[] num, mark;
int i, flag;
num = new int[n + 1];
mark = new int[n];
for (i = 0; i <= n; ++i)
num[i] = 0;
do {
for (i = 0; i < n; ++i)
mark[i] = 0;
flag = 0;
++num[0];
for (i = 0; i < n; ++i) {
if (num[i] == n) {
num[i] = 0;
++num[i + 1];
}
++mark[num[i]];
// 各位数组单元有无重复
if (mark[num[i]] > 1) {
flag = 1;
break;
}
}
if (flag == 0)
output(num, arr);
} while (num[n] == 0);
}
public static void main(String[] args) {
int[] n = {12, 22, 2, 4, 6};
permutCombi(n, n.length);
}
}