第四讲 递归原理--数组的全排列(递归+交换)
2014-12-04 15:08
197 查看
package chapter4; /** * @功能说明 : * 实现一个数组的全排列 * 这里使用了交换+递归法 * @author shaochong * @Date 2014年12月4日 下午3:06:01 */ public class pailie { static void show(char[] a){ for(int i=0; i<a.length; i++) System.out.print(a[i]+" "); System.out.println(); } static void f(char[] a, int k) { if(k==a.length-1){ show(a); return; } for(int i=k; i<a.length; i++){ {char t = a[k]; a[k]=a[i]; a[i]=t;} f(a,k+1); {char t = a[k]; a[k]=a[i]; a[i]=t;} } } public static void main(String[] args) { char[] a = "ABCD".toCharArray(); f(a,0); } }
相关文章推荐
- 由erlang的递归理解数组的全排列问题
- 用递归的思想输出一个数组的全排列,和组合
- 数组全排列的递归方法实现
- Java用递归实现的数组的全排列
- 四叉树空间索引原理及其实现 && 递归遍历叶节点并输出至数组
- 第四讲 递归原理--低碳生活答题节目
- 2013-10-29 实验之数组中元素全排列(递归思想题)
- 第四讲 递归原理--警察智力训练
- 递归求解字符数组全排列问题
- 第四题:如果一个字符数组中有重复的字符 如"abbcd" 那么如何编程打印其全排列
- 第四讲 递归原理--组合问题(标记选与不选)
- 第四讲 递归原理--交通问题
- 递归实现数组全排列
- 递归列举从数组b()中选出某些元素(允许重复)使其和等于num的所有组合
- 递归,缩进,输出数组
- 第一个数组题,是抄的,但了解了原理
- 全排列问题之递归求解
- 用递归颠倒一个数组
- 利用递归把多维数组转为一维数组的函数
- 用递归颠倒一个数组