public void init(int size) {
table = new int[size][size];
int val = 1;
for (int i = 0; i < table.length; i++) {
for (int j = 0; j < table[i].length; j++) {
table[i][j] = val++;
}
}
}
public void replaceRow(int from, int to) {
check(from, to);
int[] tmpFrom = table[from];
int[] tmpTo = table[to];
table[to] = tmpFrom;
table[from] = tmpTo;
}
public void replaceCol(int from, int to) {
check(from, to);
for (int i = 0; i < table.length; i++) {
int tempFrom = table[i][from];
int tempTo = table[i][to];
table[i][to] = tempFrom;
table[i][from] = tempTo;
}
}
public void show() {
for (int i = 0; i < table.length; i++) {
for (int j = 0; j < table[i].length; j++) {
System.out.print(table[i][j] + "\t");
}
System.out.println();
}
}
private void check(int from, int to) {
if (from >= table.length || to >= table.length)
throw new IllegalArgumentException();
}
}
/**指定の次数の正方行列を生成*/
public ArrayTable(int size) {
table = new int[size][size];
int val = 1;
for (int i = 0; i < table.length; i++) {
for (int j = 0; j < table[i].length; j++) {
table[i][j] = val++;
}
}
}
/**コピーコンストラクタ*/
public ArrayTable(ArrayTable arrayTable){
table = copy2DArray(arrayTable.table);
}
// 基本となる行列を生成
int n = 4;
SquareMatrix mat = new SquareMatrix(n);
mat.initMatrix();
int f = 1;
for (int i = 1; i <= n; i++) {
f *= i;
}
int[][] perms = new int[f][];// 全順列格納用変数
int[][] matrices = new int[f * f][];// 全行列格納用変数
// 全順列取得
int[] perm = new int[n];
for (int i = 0; i < n; i++) {
perm[i] = i;
}
Enumeration e = new PermEnum(perm);
int count = 0;
while (e.hasMoreElements()) {
int[] a = (int[]) e.nextElement();
System.out.print("{" + a[0]);
for (int i = 1; i < a.length; i++) {
System.out.print(", " + a[i]);
}
System.out.println("}");