Added transpose
This commit is contained in:
@@ -478,6 +478,20 @@ public class IntegerMatrix{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Complex operations
|
//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
|
//Object funtions
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user