给定一字符数组,求数组中字符组成的所有排列
public static void main(String[] args) { char[] origin = { 'a', 'b', 'c', 'd', 'e', 'f' }; int length = origin.length; int[] tmp = new int[length]; char[] res = new char[length]; boolean[] check = new boolean[length]; int index = 0, level = 0; while (true) { if (index >= 0 && index < length && level >= 0 && level < length) { if (!check[index]) { tmp[level] = index; res[level] = origin[index]; check[index] = true; level++; index = 0; } else { index++; } } else if (level >= length) { System.out.println(new String(res)); level = length - 1; index = tmp[level]; check[index] = false; index++; } else if (index >= length) { level--; if (level < 0) break; index = tmp[level]; check[index] = false; index++; } else { break; } } }