BFS for 3D matrices

This is a discussion on BFS for 3D matrices within the C Programming forums, part of the General Programming Boards category; I am working towards the BFS algo. My algo works completely fine with 2D array (without using pointers) but not ...

  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
    32,823
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    32,823
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    32,823
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06: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, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21