输出所有排列组合
2014-03-27 09:28
155 查看
package static1; import java.util.Arrays; public class Permutation { public static void main(String[] args){ int[] array=new int[]{1, 2,3}; permute(array,0); } public static void permute(int a[], int s) { if (s == a.length) { System.out.println(Arrays.toString(a)); } else for (int i = s; i < a.length; ++i) { swap(a, s, i); permute(a, s + 1); swap(a, s, i); } } private static void swap(int[] a,int s,int i) { int t=a[s]; a[s]=a[i]; a[i]=t; } }
相关文章推荐
- 编程题:输出字符集合的所有排列组合。
- JAVA 输出指定字符串所有排列组合
- 输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻
- 输出4个整数(不重复)的所有排列组合
- 输入N个数,输出所有可能的排列组合(6+个小时啊,耶稣~)
- 输出n对括号的所有有效排列组合
- 给定一个字符串,输出所有的排列组合方式
- 输出字符串的所有排列组合情况
- 输出字符串的所有排列组合
- 任意数字序列“123456”之类,输出它们所有的排列组合
- 输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻
- 输出1,2,2,3,4,5的所有排列组合,4不能在第3位,3和5不能相邻
- 输出数组的所有元素的排列组合(递归)
- 任意数字、字符序列,输出它们所有的排列组合
- Swift - 排列组合之全排列 (输入一个字符串,输出该字符串包含的字符的所有组合)
- 输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻
- 输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻
- 针对如"123456"之类的任意字符序列,输出它们所有的排列组合
- 输出给定集合的所有排列与组合-python
- 面试题:输出1,2,2,3,4,5的所有排列组合,4不能在第三位,3和5不能相邻