Sparse Arrays, take three
Recall the sparse arrays of HW 4. Re-implement the SparseArray class of
that homework but this time use a binary search tree rather than a linked list,
in order to improve performance. Other than that the requirements are still the
same:
- Program a constructor and destructor and a read_element and write_element
method to allow the user to access parts of the array. A read on a position
where the user has not written anything should return a 0.
- Overload the [] operator so that the user can use this class as if it were
an array. (This requires some thought to decide what the proper behavior should
be. Include a detailed comment explaining what your implementation does and
why)
- The memory used in your implementation should be proportional to the
number of non-zero elements the user currently has in the array. It should
not depend on the positions where the user is writing. In particular, it
would be nice if you removed elements that contain a 0, since this is the
default value of the array, in order to save space.
As usual, submit a header file, an implementation file and a test program.