Added transpose

This commit is contained in:
2022-02-03 19:59:20 +00:00
parent 8f09e321f1
commit 2878ba6a02

View File

@@ -478,6 +478,20 @@ public class IntegerMatrix{
}
//Complex operations
public IntegerMatrix transpose(){
//Create a new grid
int[][] newGrid = new int[getNumCols()][getNumRows()];
//Traverse every element in the existing grid and add each column to the new grid as a row
for(int col = 0;col < getNumCols();++col){
for(int row = 0;row < getNumRows();++row){
newGrid[col][row] = grid[row][col];
}
}
//Return the new matrix
return new IntegerMatrix(newGrid);
}
//Object funtions
@Override