This pull request addresses issues related to row and column insertion boundaries in the Matrix class, as well as correcting index checks for matrix operations. The changes ensure that rows and columns can be inserted correctly at the end of the matrix and that boundary conditions are handled appropriately, avoiding potential index out of bounds errors.
Changes Made
Row Insertion Correction
Updated the Matrix.insertRow() method to insert a new row at the correct position. Previously, the insertion was occurring at m.getNumRows() - 1, which placed the new row one index before the end of the matrix. The new implementation corrects this to m.getNumRows(), allowing for proper insertion at the end of the matrix.
Column Insertion Correction
Modified the Matrix.insertColumn() method similarly to insert a new column at m.getNumCols() instead of m.getNumCols() - 1. This ensures that columns are appended correctly at the end of the matrix.
Boundary Check Adjustment
The boundary check for row indices in the matrix insertion logic has been updated. The condition previously checked for row >= mRows, which incorrectly excluded valid insertions at the last row index. The updated check now allows insertions at row > mRows, accommodating valid operations at the matrix's end.
Impact
Functionality
These fixes ensure that the matrix operations for row and column insertions behave as expected, allowing elements to be appended to the end of the matrix. The corrected boundary checks prevent out-of-bounds errors and ensure robust matrix operations.
Backward Compatibility
The changes maintain backward compatibility with existing matrix operations, as they only correct boundary conditions and insertion indices without altering the fundamental behavior of the matrix methods.
Overview
This pull request addresses issues related to row and column insertion boundaries in the
Matrix
class, as well as correcting index checks for matrix operations. The changes ensure that rows and columns can be inserted correctly at the end of the matrix and that boundary conditions are handled appropriately, avoiding potential index out of bounds errors.Changes Made
Row Insertion Correction
Matrix.insertRow()
method to insert a new row at the correct position. Previously, the insertion was occurring atm.getNumRows() - 1
, which placed the new row one index before the end of the matrix. The new implementation corrects this tom.getNumRows()
, allowing for proper insertion at the end of the matrix.Column Insertion Correction
Matrix.insertColumn()
method similarly to insert a new column atm.getNumCols()
instead ofm.getNumCols() - 1
. This ensures that columns are appended correctly at the end of the matrix.Boundary Check Adjustment
row >= mRows
, which incorrectly excluded valid insertions at the last row index. The updated check now allows insertions atrow > mRows
, accommodating valid operations at the matrix's end.Impact
Functionality
These fixes ensure that the matrix operations for row and column insertions behave as expected, allowing elements to be appended to the end of the matrix. The corrected boundary checks prevent out-of-bounds errors and ensure robust matrix operations.
Backward Compatibility
The changes maintain backward compatibility with existing matrix operations, as they only correct boundary conditions and insertion indices without altering the fundamental behavior of the matrix methods.