Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transpose 1D array of leading dimension N

how can i transpose an 1d array of leading dimension N, without extra space ? any language is fine

like image 403
Simon Avatar asked Apr 02 '10 12:04

Simon


1 Answers

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;
like image 199
Yane Boltrel Yan'son Avatar answered Sep 22 '22 15:09

Yane Boltrel Yan'son