全排列算法

 

全排列

public class permutation {
public static void permutation(char []ss , int i){
if(ss==null||i<0||i>ss.length){
return ;
}

if(i== ss.length-1){
System.out.println(new String(ss));
}
else{
for(int j=i;j<ss.length;j++){

char temp = ss[j];
ss[j]= ss[i];
ss[i]= temp;
permutation(ss,i+1);
temp = ss[j];
ss[j]= ss[i];
ss[i]= temp;
}

}
}
public static void main(String[] args) {
char []ss =new char[]{'a','b','c','d'};
int []num=new int [5];
permutation(ss , 0);
}

}

posted @ 2019-03-06 19:10  迷迷0糊糊  阅读(149)  评论(0编辑  收藏  举报