JavaCompilerCore/test/javFiles/Matrix.jav

42 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-08-28 13:42:51 +00:00
import java.util.Vector;
class Matrix extends Vector<Vector<Integer>> {
2017-05-19 15:40:47 +00:00
Matrix mul_rec(Matrix m) {
2017-08-28 13:42:51 +00:00
auto v1 = new Vector<Integer>();
auto v2 = new Vector<Integer>();
auto i = 0;
2017-05-19 15:40:47 +00:00
while(i < m.size()) {
2017-08-28 13:42:51 +00:00
auto v;
2017-05-19 15:40:47 +00:00
v = m.elementAt(i);
v2.addElement(v.remove(v.size()-1));
i++;
}
Matrix ret;
if (m.elementAt(0).size() > 0) {
ret = this.mul_rec(m);
}
else {
ret = new Matrix();
i = 0;
while (i < this.size()) {
2017-08-28 13:42:51 +00:00
ret.addElement(new Vector<Integer>());
2017-05-19 15:40:47 +00:00
i++;
}
}
i = 0;
while (i < this.size()) {
int erg = 0;
2017-08-28 13:42:51 +00:00
auto j;
2017-05-19 15:40:47 +00:00
j = 0;
while (j < v2.size()) {
erg = erg + this.elementAt(i).elementAt(j).intValue()
* v2.elementAt(j).intValue();
j++;
}
ret.elementAt(i).addElement(erg);
i++;
}
return ret;
}
}