我需要帮助反转一个bitmatrix,我有两个函数,我应该用它。第一个函数交换行,另一个函数将两者相加。我需要在反函数中使用这两个。
void Bitmatrix::Swap_Rows(int r1, int r2) {
string temp;
if(r1 < 0 || r2 < 0) return;
if(r1 > M.size() || r2 > M.size()) return;
temp = M[r1];
M[r1] = M[r2];
M[r2] = temp;
}
void Bitmatrix::R1_Plus_Equals_R2(int r1, int r2) {
if(r1 < 0 || r2 < 0) return;
if(r1 >= M.size() || r2 >= M.size()) return;
for(int i = 0; i < M[1].size(); i++) {
M[r1][i] = (M[r1][i] + M[r2][i]) % 2;
M[r1][i] += '0';
}
}
//As of now I have this, but not sure how to do the rest.
Bitmatrix *Inverse(Bitmatrix *m) {
if(m->Rows() != m->Cols()) return NULL; //if not square
Bitmatrix Inv = new Bitmatrix(m->Rows(), m->Cols());
for(int i = 0; i < Inv.size(); i++) {
for(int j = i+1; j < Inv.size(); j++) {
if(m[i][i] != '1') {
R1_Plus_Equals_R2(
}
}
}
}