how to transpose a 2D matrix in place?
Wikipedia had an article In-place matrix transposition. The article covers non-square matrices.
http://en.wikipedia.org/wiki/In-place_matrix_transposition
for (int i=0; i<n; i++) {
for (int j=0; j<i; j++) {
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With