  # Functionality of 3D matrix in 1D matirx ??

273 views

Can someone help to write a function to give demonstrate the functionality of 3D matrix in 1D matrix.

Function Prototype:

``````void set (int value,int indexX,int indexY,int indexZ, int [] 1dArray);
`````` posted Oct 29, 2013
Should not be in this way

for (int x = 0, k=0; x < X; x++)
for (int y = 0; y < Y; y++)
for (int z = 0; z < Z; z++)
1dArray[k++] = value[x][y][z]

Though not understood your question correctly.

Following pattern may be useful

Taking an example for 2D which can be enhanced for 3D and further

A(ij) = 1 2 3
4 5 6
7 8 9

R = elements in one row

B(x) = 1 2 3 4 5 6 7 8 9

x = (i * R) + j answer Nov 6, 2013
Similar Questions

How to implement a function to check whether there is a path for a string in a matrix of characters? It moves to left, right, up and down in a matrix, and a cell for a movement. The path can start from any entry in a matrix. If a cell is occupied by a character of a string on the path, it cannot be occupied by another character again.

You have a 2D matrix. Only two ZEROs in matrix.
Find the path from 1st zero to 2nd zero with least sum.

``````1       6       8       9       0       3

4       9       -5      5       11      13

8       9       44      23      15      -20

7       9       7       -13     14      11

0       16      23      31      16      7

67      5       4       23      21      19
``````

``````1       6       8       9       0  ----> 3
|
4       9       -5      5       11      13
|
8       9       44      23      15      -20
|
7 <---- 9 <---- 7 <--- -13 <--- 14 <---  11
|
0       16      23      31      16        7

67      5       4       23      21       19
``````