Class SparseMatrix

java.lang.Object
  extended by SparseMatrix

public class SparseMatrix
extends java.lang.Object


Nested Class Summary
 class SparseMatrix.Node
           
 
Constructor Summary
SparseMatrix(int r, int c)
          Create a new sparse matrix of integers with r rows and c columns.
 
Method Summary
 int getByColumn(int row, int col)
          Gets the value stored at the given row and column of this sparse matrix by scanning down the given column.
 int getByRow(int row, int column)
          Gets the value stored at the given row and column of this sparse matrix by scanning across the given row.
 int getNumColumns()
          Get the number of columns in this sparse matrix.
 int getNumElementsInColumn(int column)
          Gets the number of elements stored in the given column of this sparse matrix (for debugging purposes).
 int getNumElementsInRow(int row)
          Gets the number of elements stored in the given row of this sparse matrix (for debugging purposes).
 int getNumRows()
          Get the number of rows in this sparse matrix.
 void set(int value, int row, int column)
          Set the given row and column of this sparse matrix to the given value.
 SparseMatrix transpose()
          Returns the transpose of this sparse matrix.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseMatrix

public SparseMatrix(int r,
                    int c)
Create a new sparse matrix of integers with r rows and c columns. If r or c is invalid, a 5 X 5 matrix is created. This sparse matrix will initially represent a matrix containing only zeroes.

Parameters:
r - The number of rows in the sparse matrix.
c - The number of columns in the sparse matrix.
Method Detail

getNumRows

public int getNumRows()
Get the number of rows in this sparse matrix.

Returns:
The number of rows in this sparse matrix.

getNumColumns

public int getNumColumns()
Get the number of columns in this sparse matrix.

Returns:
The number of columns in this sparse matrix.

set

public void set(int value,
                int row,
                int column)
Set the given row and column of this sparse matrix to the given value.

Parameters:
value - The value to store in the sparse matrix.
row - The row where the value is to be stored.
column - The column where the value is to be stored.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the row or column is invalid.

getByRow

public int getByRow(int row,
                    int column)
Gets the value stored at the given row and column of this sparse matrix by scanning across the given row.

Parameters:
row - The row of the desired value.
column - The column of the desired value.
Returns:
The value stored at the given row and column.

getByColumn

public int getByColumn(int row,
                       int col)
Gets the value stored at the given row and column of this sparse matrix by scanning down the given column.

Parameters:
row - The row of the desired value.
column - The column of the desired value.
Returns:
The value stored at the given row and column.

getNumElementsInRow

public int getNumElementsInRow(int row)
Gets the number of elements stored in the given row of this sparse matrix (for debugging purposes).

Parameters:
row - The desired row to analyze.
Returns:
The number of elements stored in the given row in this sparse matrix.

getNumElementsInColumn

public int getNumElementsInColumn(int column)
Gets the number of elements stored in the given column of this sparse matrix (for debugging purposes).

Parameters:
column - The desired column to analyze.
Returns:
The number of elements stored in the given column in this sparse matrix.

transpose

public SparseMatrix transpose()
Returns the transpose of this sparse matrix.

Returns:
A new sparse matrix containing the transpose of this sparse matrix.