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?

Printable View

- 08-23-2010sattyBFS 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? - 08-23-2010satty
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;

}}}}

}

- 08-23-2010Salem
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. - 08-23-2010satty
my 3 D array is an adjacency matrix but multiple times.

I mean i have 4 different matrices of 6x 6 dimensions. - 08-23-2010Salem
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". - 08-23-2010satty
thanks!

- 08-23-2010Salem
No problem - glad you sorted it out!