139k views
3 votes
Multidimensional arrays can be stored in row major order, as in C , or in column major order, as in Fortran. Develop the access functions for both of these arrangements for three-dimensional arrays.

User Saver
by
5.4k points

1 Answer

6 votes

Answer:

Access functions explained below

Step-by-step explanation:

Access functions for Three Dimensional Arrays:

Let M, N and P refer to the size of the 1st 2nd and 3rd dimensions respectively.

Element_Size is the memory size the array element.

Generic access functions for Row Major:

If character data is used then Element_Size is 1.

For i=0 to P do

For i=0 to N do

For i=0 to M do

Address_of _array[i, j, k] = address_of_array[0,0,0] + (i * P + j * N + k) * Element_Size

Store data into the Address_of _array[i, j, k]

Or

Display data from Address_of _array[i, j, k]

end

end

end

Generic access function for Column Major:

if For i=0 to M do

For i=0 to N do

For i=0 to P do

Address_of _array[i, j, k] = address_of_array[0,0,0] + (i * M + j * N + k) * Element_Size

Store data into the Address_of _array[i, j, k]

Or

Display data from Address_of _array[i, j, k]

end

end

end

User Scav
by
6.3k points