Skip to content

Commit

Permalink
factor out function for the gauss jordan vector in original order
Browse files Browse the repository at this point in the history
  • Loading branch information
Arne Mertz committed Jul 10, 2016
1 parent a8248d5 commit 76288c9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions 2016-07-refactoring-session-02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ struct GaussJordanMatrix {
}
y[rowIndex] /= diagonalElement;
}

Vector getVectorInOriginalOrder() {
Vector v = y;
for (int i=0;i<rowCount();++i) {
std::swap(v[i], v[rowIndices[i]]);
}
return v;
}
};

// Solve y=m*x for x
Expand All @@ -97,10 +105,7 @@ Vector gaussJordanElimination(Matrix m, Vector y) {
}
}
}
for (int i=0;i<rowCount;++i) {
std::swap(gaussJordan.y[i], gaussJordan.y[gaussJordan.rowIndices[i]]);
}
return gaussJordan.y;
return gaussJordan.getVectorInOriginalOrder();
}


Expand Down

0 comments on commit 76288c9

Please sign in to comment.