/**
* 类名:Test6.java
* 说明:全排列
*/
public class Test6 {
public static <Type> void perm(Type[] a){
perm(a,0,a.length-1);
}
private static <Type>void perm(Type[]a, int low,int high){
if(low == high){
for(int i = 0; i<=high;i++)
System.out.print(a[i]);
System.out.println();
}else{
for(int i = low;i<=high;i++){
Type temp = a[low];//和后面的交换
a[low] = a[i];
a[i] = temp;
perm(a,low+1,high);
Type temp2 = a[low];//换回来
a[low] = a[i];
a[i] = temp2;
}
}
}
public static void main(String[] args) {
Character[] c = new Character[]{'a','b','c'};
perm(c);
}
}
递归分治求全排列
最新推荐文章于 2023-03-14 21:16:51 发布