日期:2014-05-20 浏览次数:20941 次
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javatest;
/**
*
* @author ZangXT
*/
public class Main {
public static void main(String[] args) {
int a[] = {1, 2, 3,4};
perm(a, 0, a.length - 1);
}
public static void perm(int[] buf, int start, int end) {
if (start == end) {
for (int i = 0; i <= end; i++) {
System.out.print(buf[i] + " ");
}
System.out.println();
} else {
for (int i = start; i <= end; i++) {
swap(buf, start, i);
perm(buf, start + 1, end);
swap(buf, start, i);
}
}
}
private static void swap(int buf[], int i, int j) {
int temp = buf[i];
buf[i] = buf[j];
buf[j] = temp;
}
}
------解决方案--------------------
好麻烦,数值少还好,一旦数值很大时就会占用很大
------解决方案--------------------