首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

AllPermutation罗列全排列

2012-11-05 
AllPermutation列举全排列由于在排版系统中的需要今天写了一个可以列举出全排列的AllPermutation类(主要是

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!

热点排行