I am trying to transpose a matrix built with vectors.
Here is the transpose function I wrote:
void transpose(std::vector>&am
You swap (i,j) with (j,i) twice! That's why it has no effect.
You should only work on one half of your matrix. Plus minors improvements, we get:
void transpose(std::vector<std::vector<int>>& fill_mat)
{
using size_type = decltype(fill_mat)::size_type; // better use your matrix' size type
for (size_type i = 0; i < fill_mat.size(); ++i) {
for (size_type j = 0; j < i; ++j) {
using std::swap; // see swap idiom
swap(fill_mat[i][j], fill_mat[j][i]);
}
}
}