Data Structures and Algorithms with Object-Oriented Design Patterns in C#
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 DynamicArray 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_inline60281 is the size of the tex2html_wrap_inline57621 dimension ( tex2html_wrap_inline60285).

   program3043
Program: MultiDimensionalArray fields.

The second field, factors, is also an array of length n. The tex2html_wrap_inline60289 element of the factors array corresponds to the factor tex2html_wrap_inline60269 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 © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.