package structure; import org.junit.Test; /*递归全排列*/ public class perm { public void perm1(char[] a,int start){ if(start==a.length-1){ for(int i=0;i<a.length;i++){ System.out.print(a[i]); } System.out.println(); }else { for(int i=start;i<a.length;i++){ swqp(a,start,i); perm1(a,start+1); swqp(a,start,i); } } } public void swqp(char[] a,int i,int j){ char t=a[i]; a[i]=a[j]; a[j]=t; } @Test public void test(){ char[] a={‘a‘,‘b‘,‘c‘}; perm1(a,0); } }
原文地址:https://www.cnblogs.com/UalBlog/p/10963427.html
时间: 2024-10-10 07:28:32