日期:2014-05-20 浏览次数:20660 次
import java.util.ArrayList;
import java.util.List;
public class Test {
static List<int[]> allSorts = new ArrayList<int[]>();
public static void permutation(int[] nums, int start, int end) {
if (start == end) {
int[] newNums = new int[nums.length];
for (int i=0; i<=end; i++) {
newNums[i] = nums[i];
}
allSorts.add(newNums);
} else {
for (int i=start; i<=end; i++) {
int temp = nums[start];
nums[start] = nums[i];
nums[i] = temp;
permutation(nums, start + 1, end);
nums[i] = nums[start];
nums[start] = temp;
}
}
}
public static void main(String[] args) {
int[] numArray = {1, 2, 3, 4};
permutation(numArray, 0, numArray.length - 1);
int[][] a = new int[allSorts.size()][];
allSorts.toArray(a);
for (int i=0; i<a.length; i++) {
int[] nums = a[i];
for (int j=0; j<nums.length; j++) {