读书人

AllPermutation罗列全排列

发布时间: 2012-11-05 09:35:12 作者: rapoo

AllPermutation列举全排列

由于在排版系统中的需要今天写了一个可以列举出全排列的AllPermutation类(主要是按照字典序的顺序):

?

AllPermutation permutation =new AllPermutation(new int[]{1,2,3,4});int[] temp=null;while((temp=permutation.next())!=null){for (int index = 0; index < temp.length; index++){int j = temp[index];System.out.print(j+",");}System.out.println("");}

?

?

输出结果 写道1,2,4,3,
1,3,2,4,
1,3,4,2,
1,4,2,3,
1,4,3,2,
2,1,3,4,
2,1,4,3,
2,3,1,4,
2,3,4,1,
2,4,1,3,
2,4,3,1,
3,1,2,4,
3,1,4,2,
3,2,1,4,
3,2,4,1,
3,4,1,2,
3,4,2,1,
4,1,2,3,
4,1,3,2,
4,2,1,3,
4,2,3,1,
4,3,1,2,
4,3,2,1,
no more permutaion!

读书人网 >编程

热点推荐