Java Matrix Transpose transpose2d(Object[][] array)

Here you can find the source of transpose2d(Object[][] array)

Description

A method for transposing square 2D arrays in-place.

License

Open Source License

Declaration

public static void transpose2d(Object[][] array) 

Method Source Code

//package com.java2s;

public class Main {
    /**//ww w  .  ja va 2  s.  c o  m
     * A method for transposing square 2D arrays in-place.
     */
    public static void transpose2d(Object[][] array) {
        if (array == null) {
            throw new IllegalArgumentException("Array must not be null");
        }

        for (int j = 0; j < array[0].length; j++) {
            for (int i = j + 0; i < array.length; i++) {
                swap2d(array, i, j, j, i);
            }
        }
    }

    /**
     * A method for swapping matrix cells in-place.
     * @param array The target array.
     * @param c1 The 1st swap column.
     * @param r1 The 1st swap row.
     * @param c2 The 2nd swap column.
     * @param r2 The 2nd swap row.
     */
    public static void swap2d(Object[][] array, int c1, int r1, int c2, int r2) {
        if (array == null) {
            throw new IllegalArgumentException("Array must not be null");
        }

        Object swap = array[c1][r1];
        array[c1][r1] = array[c2][r2];
        array[c2][r2] = swap;
    }
}

Related

  1. transpose(int[][] matrix)
  2. transpose(int[][][] as, int A, int[][][] ast)
  3. transpose(long[] a, double offset)
  4. transpose(Object[][] matrix)
  5. transpose(Object[][] matrix)
  6. transpose2DArray(Double[][] data)
  7. transpose3x3Matrix(float[][] m)
  8. transpose4x4(float m[], float t[])
  9. transpose_image(Object source, int width, int height)