Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

An Implementation

 

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 gif.

Program gif 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 tex2html_wrap_inline60002 is the size of the tex2html_wrap_inline57340 dimension ( tex2html_wrap_inline60006).

   program3061
Program: MultiDimensionalArray fields.

The second field, factors, is also an array of length n. The tex2html_wrap_inline60010 element of the factors array corresponds to the factor tex2html_wrap_inline59990 given by Equation gif.

The third field, data, is a one-dimensional array used to hold the elements of the multi-dimensional array in row-major order.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.