# Thread: BFS for 3D matrices

1. ## BFS for 3D matrices

I am working towards the BFS algo.
My algo works completely fine with 2D array (without using pointers) but not with 3D (with pointers like ***array) .....
can some1 help why?

2. this is my code:
Code:
```bfs(int ***array2, int *visited, int start){
int q[nodes],rear=-1,front=-1,i,j;
q[++rear]=start;
visited[start]=1;
while(rear != front)
{
start = q[++front];
printf("%c \t",start+49);
for (i=0; i<iter; i++){
for (j=0; j<nodes; j++){
if(array2[i][start][j] && !visited[j])
{
q[++rear]=i;
visited[j]=1;
}}}}
}```
n I am getting a Bus error!

3. It's hard to imagine how much worse you could make your code formatting.

Seriously, random indentation and multiple braces on a line is NOT the way to go.

Also, you need to show us what exactly "a 3D array" looks like when you call this function.

Simply saying
int foo[2][2][2];

then passing it to a function expecting int*** just isn't going to work.

Replacing [] with * only works for ONE level, it is not applied recursively.

4. my 3 D array is an adjacency matrix but multiple times.
I mean i have 4 different matrices of 6x 6 dimensions.

5. My dinner has several vegetables colours red, green and orange - what are they?

HOW the hell are we supposed to debug from that pithy comment?

SHOW us what it is, don't just describe it in vague "it's an adjacency matrix".

6. thanks!

7. No problem - glad you sorted it out!