A two-dimensional array of values in which most elements are zero is called a sparse array. Because most elements have a value of zero, memory can be saved by storing only the non-zero values along with their row and column indexes.
Write a class SparseArrayEntry
that keeps track of the row
, column
, and value
(all int
values) of an element in a sparse array. The constructor will take those three values as parameters. Write the methods getRow
, getCol
, getValue
, and setValue
for this class.
Then write a program SparseRandomWalker
that tracks a random walker's location using an ArrayList
of SparseArrayEntry
objects.