[求助] 递归
下面是数字排列问题 别人写的个递归.....
public class Permutations {
private static void perm(char[] a, int n) {
if (n == 1) {
System.out.println(a);
return;
}
for (int i = 0; i < n; i++) {
swap(a, i, n-1);
perm(a, n-1);
swap(a, i, n-1);
}
}
// swap the characters at indices i and j
private static void swap(char[] a, int i, int j) {
char c;
c = a[i]; a[i] = a[j]; a[j] = c;
}
public static void main(String[] args) {
char[] chars = {'2','6','7','5'};
perm(chars, 4);
}
}
这种循环的递归,什么时候能够用? 设计思路是怎样的?