Adding MatrixRemoveRow/Column
This commit is contained in:
		@ -10,4 +10,30 @@ public class Array{
 | 
			
		||||
        }
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean[][] MatrixRemoveRow(boolean[][] o, int row){
 | 
			
		||||
        boolean[][] newMatrix = new boolean[o.length - 1][o[0].length];
 | 
			
		||||
        int newRow = 0;
 | 
			
		||||
        for (int i = 0; i < o.length; i++) {
 | 
			
		||||
            if(i == row)
 | 
			
		||||
                i++;
 | 
			
		||||
            newMatrix[newRow] = o[i];
 | 
			
		||||
            newRow++;
 | 
			
		||||
        }
 | 
			
		||||
        return newMatrix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean[][] MatrixRemoveColumn(boolean[][] o, int col){
 | 
			
		||||
        boolean[][] newMatrix = new boolean[o.length][o[0].length - 1];
 | 
			
		||||
        for (int i = 0; i < o.length; i++) {
 | 
			
		||||
            int newCol = 0;
 | 
			
		||||
            for(int j = 0; j < o[0].length; j++){
 | 
			
		||||
                if(j == col)
 | 
			
		||||
                    j++;
 | 
			
		||||
                newMatrix[i][newCol] = o[i][j];
 | 
			
		||||
                newCol++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return newMatrix;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -23,4 +23,37 @@ class ArrayTest {
 | 
			
		||||
        a[1][1] = true;
 | 
			
		||||
        assertArrayEquals(b, c);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void matrixRemoveRow() {
 | 
			
		||||
        boolean[][] a = new boolean[][] {
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
                {false, false, false},
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
        };
 | 
			
		||||
        boolean[][] b = new boolean[][] {
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        boolean[][] result = Array.MatrixRemoveRow(a, 1);
 | 
			
		||||
        assertArrayEquals(b, result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void matrixRemoveColumn() {
 | 
			
		||||
        boolean[][] a = new boolean[][] {
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
                {false, false, false},
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
        };
 | 
			
		||||
        boolean[][] b = new boolean[][] {
 | 
			
		||||
                {true, true},
 | 
			
		||||
                {false, false},
 | 
			
		||||
                {true, true},
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        boolean[][] result = Array.MatrixRemoveColumn(a, 1);
 | 
			
		||||
        assertArrayEquals(b, result);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user