/** * @param args */ public static void main(String[] args) { char[] raw = "12345".toCharArray(); perm(raw, 4); // System.out.println("==========================="); // System.out.println(Arrays.toString(raw)); } static void perm(char[] data, int k) { if (k == 0) { System.out.println(Arrays.toString(data)); } else { for (int i = 0; i <= k; i++) { char t = data[i]; data[i] = data[k]; data[k] = t; perm(data, k - 1); t = data[i]; data[i] = data[k]; data[k] = t; } } }
全排列递归实现(二)
时间: 2024-10-08 08:16:13