how can i transpose an 1d array of leading dimension N, without extra space ? any language is fine
My solution for 1D in-place Matrix transposition
mn = M*N; /* M rows and N columns */
q = mn - 1;
i = 0; /* Index of 1D array that represents the matrix */
do {
k = (i*M) % q;
while (k>i) k = (M*k) % q;
if (k!=i) Swap(k, i);
} while ( ++i <= (mn -2) );
/* Update row and column */
matrix.M = N;
matrix.N = M;
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