Java Matrix Flip flipOverY(T[][] arr)

Here you can find the source of flipOverY(T[][] arr)

Description

Flips the 2D Array as if around a Vertical Axis.

License

Open Source License

Parameter

Parameter Description
arr a parameter

Declaration

public static <T> void flipOverY(T[][] arr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  ww w  .j a  va2  s.co m
     * Flips the 2D Array as if around a Vertical Axis. Does not preserve original array.
     * @param arr
     */
    public static <T> void flipOverY(T[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            flipOverY(arr[i]);
        }
    }

    /**
     * Flips Array as if around a Vertical Axis. Does NOT preserve original array
     * @param arr
     */
    public static <T> void flipOverY(T[] arr) {
        int z = arr.length - 1;

        for (int a = 0; a < z; a++) {
            T tmp = arr[a];
            arr[a] = arr[z];
            arr[z] = tmp;
            z--;
        }
    }
}

Related

  1. flipInPlace(int[][] theArray)
  2. flipLeftToRight(int[][] theArray)
  3. flipLR(int[][] x)
  4. flipOverX(T[][] arr)