package chapter1; public class Arragement { /** * 全排列问题 * * @param args */ public static void swap(Object[] a, int i, int j) { Object temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void perm(Object[] list, int i, int n) { int j; if (i == n) { for (j = 0; j <= n; j++) { System.out.print(list[j] + " "); } System.out.println(); } else { for (j = i; j <= n; j++) { swap(list, i, j); // abc跟随 perm(list, i + 1, n); // abc所有组合 swap(list, i, j); } } } public static void main(String[] args) { Character list[] = { 'a', 'b', 'c' }; perm(list, 0, 2); } }