字符数组的全排列

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);
    }

}

 

posted @ 2019-06-02 16:57  Uarealoser  阅读(371)  评论(0编辑  收藏  举报