Java List Rotate rotateRowsOfMatrix(List> matrix)

Here you can find the source of rotateRowsOfMatrix(List> matrix)

Description

rotate Rows Of Matrix

License

Open Source License

Declaration

public static List<List<Integer>> rotateRowsOfMatrix(List<List<Integer>> matrix) 

Method Source Code


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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<List<Integer>> rotateRowsOfMatrix(List<List<Integer>> matrix) {
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        for (int i = 0; i < matrix.size(); i++) {
            List<Integer> row = matrix.get(i);
            List<Integer> newRow = new ArrayList<Integer>();
            Integer temp0 = row.get(0);
            Integer temp1 = row.get(1);
            Integer temp2 = row.get(2);
            Integer temp3 = row.get(3);
            switch (i) {
            case 0: {
                newRow.add(temp1);//from  ww  w  . ja  va2  s  .  c  o  m
                newRow.add(temp2);
                newRow.add(temp3);
                newRow.add(temp0);
                break;
            }
            case 1: {
                newRow.add(temp2);
                newRow.add(temp3);
                newRow.add(temp0);
                newRow.add(temp1);
                break;
            }
            case 2: {
                newRow.add(temp3);
                newRow.add(temp0);
                newRow.add(temp1);
                newRow.add(temp2);
                break;
            }
            case 3: {
                newRow.add(temp3);
                newRow.add(temp2);
                newRow.add(temp1);
                newRow.add(temp0);
                break;
            }
            }
            result.add(newRow);
        }
        return result;
    }
}

Related

  1. rotate(final List list, int n)
  2. rotate(List a)
  3. rotate(List data, int n)

  4. HOME | Copyright © www.java2s.com 2016