過去ログ

kasama
#18623 追加:クラスPermutationの内容
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Permutation {
 private int num = 0;
 private List elementList = null;
 private List permutationList = null;
 public Permutation(List elementList) {
  this(elementList, elementList.size());
 }
 public Permutation(List elementList, int num) {
  this.num = num;
  this.elementList = elementList;
 }
 public List getList() {
  permutationList = new ArrayList();
  eachCreate(new ArrayList());
  return permutationList;
 }
 private void eachCreate(List indexList) {
  if (indexList.size() >= num) {
   List permutationElementList = new ArrayList();
   for (int i = 0; i < indexList.size(); ++i) {
    Integer index = (Integer) indexList.get(i);
    permutationElementList.add(elementList.get(index.intValue()));
   }
   permutationList.add(permutationElementList);
   return;
  }
  for (int i = 0; i < elementList.size(); ++i) {
   Integer index = new Integer(i);
   if (indexList.contains(index)) continue;
   List newIndexList = new ArrayList(indexList);
   newIndexList.add(index);
   eachCreate(newIndexList);
  }
 }
}
和歌山   5月15日(木) 2:11:32   MAIL:kasama@s34.co.jp   18624

過去問題一覧へ戻る