February 26th, 2012, 02:23 PM
Sparse 2 dimensional array
i created a program which uses Sparse 2 dimensional array, but i am not sure if i did it in the right way .
this is the instruction i have:
Create a constructor and a destructor. The constructor should take as input the size of the array (consider only square NxN arrays, so only one dimension is needed) and the thickness of the ribbon. To make this precise, if supplied with a thickness parameter t, you may assume that the element [0,t] (i.e. the (t+1)-th element of the first row) is where the useless area begins on the right. Similarly, the element [t,0] is where the useless area begins on the left. The border of the useless areas moves diagonally down and to the right, i.e. it consists of [1,t+1],[2,t+2],... and [t+1,1],[t+2,2],... The above example has thickness 3.
The space for the 2-d array should be dynamically allocated and must be large enough to fit the useful data only.
Create methods for random read and write access to the array as in the case of 1-d arrays.
Overload the  and << operators, as in the case of 1-d arrays. Think carefully about what the  operator should return and how it should work. Ideally we would like this to behave in a manner similar to standard 2-d arrays (i.e. accessing elements in the normal way, like x).
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.