In this section we illustrate the implementation of a
multi-dimensional array using a one-dimensional array.
We do this by defining a class called MultiDimensionalArray
that is very similar to the Array class
defined in Section .
Program defines the fields
of the MultiDimensionalArray class.
Altogether three fields are used.
The first, dimensions is an array of length n,
where n is number of dimensions
and
is the size of the
dimension (
).
Program: MultiDimensionalArray fields.
The second field, factors,
is also an array of length n.
The element of the factors array
corresponds to the factor
given by Equation
.
The third field, data, is a one-dimensional array used to hold the elements of the multi-dimensional array in row-major order.