samedi 31 janvier 2015

Transpose a matrix without a buffering one


How is it possible to transpose a MxN matrix without using a "buffering" matrix? In the latter case it's easy and quite the "classic" approach...


Given a matrix[M][N], I would like to put it into a void transpose_matrix(int matrix[][]) function which operates directly on the matrix passed as reference which, as previosly said, would edit the matrix memory space to transpose its elements.


e.g:


A =



1 2 3 4
5 6 7 8
9 1 2 3


A after transposing itself (without pretty printing)[1]:



1 5 9 2
6 1 3 7
2 4 8 3


Thanks!


[1]: Printing the matrix as if it was actually a "new" NxM matrix.





Aucun commentaire:

Enregistrer un commentaire