In view of the recent interview, need to review the algorithm or something, the previous written algorithms to send out.
public class Test {public static char[] Text = {' A ', ' C ', ' C ', ' d '};p ublic static void Main (string[] args) {permutation ( Text, 0, text.length); System.exit (0);} /** * Full Array output * * @param a * [] array of characters to output * @param m * The starting position of the output character array * @param n * output character array length */public static voi D permutation (char a[], int m, int n) {if (M < n-1) {permutation (A, M + 1, n);//start with the 2nd element, and/or start with the first element from the 2nd element, and then from a The 2nd element begins the full-array//Last-restore sequence, looping char t;for (int i = m + 1; i < n; i++) {if (a[m]! = A[i]) {t = a[m];//interchange A[m] = a[i];a[i] = t; Permutation (A, M + 1, n); t = a[m]; Restore a[m] = a[i];a[i] = t;}}} else {Printresult (a);}} /** * Outputs the specified character array */public static void Printresult (char[] text) {for (int i = 0; i < text.length; i++) {System.out.print (t Ext[i]);} System.out.println ();}}
The Java implementation is fully aligned