Fixed addCol bug

This commit is contained in:
2022-02-17 21:28:05 +00:00
parent 67fcfa1344
commit 9883a615be

View File

@@ -1,7 +1,7 @@
//Matrix/src/main/java/com/mattrixwv/IntegerMatrix.java //Matrix/src/main/java/com/mattrixwv/IntegerMatrix.java
//Mattrixwv //Mattrixwv
// Created: 02-01-22 // Created: 02-01-22
//Modified: 02-10-22 //Modified: 02-17-22
package com.mattrixwv.matrix; package com.mattrixwv.matrix;
@@ -59,7 +59,7 @@ public class IntegerMatrix{
//Return the new grid //Return the new grid
return newGrid; return newGrid;
} }
protected boolean isSquare(){ public boolean isSquare(){
if(getNumRows() == 0){ if(getNumRows() == 0){
return false; return false;
} }
@@ -291,7 +291,7 @@ public class IntegerMatrix{
public void addCol(int[] elements){ public void addCol(int[] elements){
//Make sure the number of rows is valid //Make sure the number of rows is valid
if(grid.length == 0){ if(grid.length == 0){
grid = new int[1][elements.length]; grid = new int[elements.length][1];
} }
else if(grid.length == elements.length){ else if(grid.length == elements.length){
//Copy all existing data into the new grid //Copy all existing data into the new grid