title: In-place transposition of a matrix
body: <p>Is it possible to transpose a <code>(m,n)</code> matrix in-place, giving that the matrix is represented as a single array of size <code>m*n</code> ? </p>
  
  <p>The usual algorithm </p>
  
  <pre><code>transpose(Matrix mat,int rows, int cols ){
      //construction step
      Matrix tmat;
      for(int i=0;i&lt;rows;i++){
        for(int j=0;j&lt;cols;j++){
         tmat[j][i] = mat[i][j];
        }
      }
   }
  </code></pre>
  
  <p>doesn't apply to a single array unless the matrix is a square matrix.
  If none, what is the minimum amount of additional memory needed??</p>
  
  <p>EDIT: 
  I have already tried all flavors of </p>
  
  <pre><code>for(int i=0;i&lt;n;++i) {
    for(int j=0;j&lt;i;++j) {
       var swap = m[i][j];
       m[i][j] = m[j][i];
       m[j][i] = swap;
    }
  }
  </code></pre>
  
  <p>And it is not correct. In this specific example, <code>m</code> doesnt even exist. In a single line 
  matrix <code>mat[i][j] = mat[i*m + j]</code>, where <code>trans[j][i]  = trans[i*n + j]</code></p>