import java.util.ArrayList;
public class Dem01 {
private int total = 0;
private ArrayList arrangeList = new ArrayList();
public Dem01() {
}
private void swap(String list[], int k, int i) {
String c3 = list[k];
list[k] = list[i];
list[i] = c3;
}
public void perm(String list[], int k, int m) {
if (k > m) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i <= m; i++) {
sb.append(list[i]).append(",");
}
if (sb.length()>0) {
sb.setLength(sb.length()-1);
}
arrangeList.add(sb.toString());
total++;
}
else {
for (int i = k; i <= m; i++) {
swap(list, k, i);
perm(list, k + 1, m);
swap(list, k, i);
}
}
}
public int getTotal() {
return total;
}
public ArrayList getArrangeList() {
return arrangeList;
}
public static void main(String args[]) {
String list[] = {"0", "1", "2", "3", "4", "5","6","7" };
Dem01 ts = new Dem01();
for(int aa=1;aa<8;aa++){
ts.perm(list, 0, aa);
for (int i = 0; i < ts.getArrangeList().size(); i++) {
System.out.println(ts.getArrangeList().get(i));
}
}
System.out.println("total:" + ts.total);
}
}
.........
7,0,1,2,3,6,5,4
7,0,1,2,3,6,4,5
7,0,1,2,3,4,6,5
7,0,1,2,3,4,5,6
total:46232