Thread: BFS for 3D matrices

  1. #1
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96

    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. #2
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96

    Exclamation

    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. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    my 3 D array is an adjacency matrix but multiple times.
    I mean i have 4 different matrices of 6x 6 dimensions.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    thanks!

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    No problem - glad you sorted it out!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C simple Matrices
    By Cyberman86 in forum C Programming
    Replies: 3
    Last Post: 05-07-2009, 05:20 PM
  2. Help getting started..matrices
    By BobDole11 in forum C Programming
    Replies: 7
    Last Post: 11-15-2008, 09:51 PM
  3. adding matrices, help with switches
    By quiet_forever in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2007, 08:21 AM
  4. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM
  5. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 09:20 AM