top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Functionality of 3D matrix in 1D matirx ??

+6 votes
459 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 by Anuj Yadav

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
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.

1 Answer

0 votes

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 by Pankaj Agarwal
Similar Questions
+5 votes

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.

+7 votes

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

Answer

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
+6 votes

Given a matrix with 1s and 0s, please find the number of groups of 1s. A group is defined by horizontally or vertically adjacent 1s.

...