Thread: How to pass mutiple matrices to a linked list

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

    How to pass mutiple matrices to a linked list

    Can someone suggest me how can i pass more than 1 matrix to a linked list to perform some operation.
    I have stored my matrices as 3D matrices.
    it is row x columns x iterations.
    say I have 10 x 10 matrix but i have 20 of them.
    I wan to pass all 20 to the next function i.e Linked list that checks th connectivity in the matrices.

    My program runs fine for the first matrix that I get from the program and then exits.
    Any suggestion is welcomed.

    thanks.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Post up how the array is declared. Also, the function in question. It sounds like it's not a contiguous memory (aka a "true") array.

  3. #3
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    the array declared is :

    Code:
    int ***array2;
     array2 = (int ***)malloc(sizeof(int **) * iter);
      for (i = 0 ;  i < iter; i++) {
        array2[i] = (int **)malloc(sizeof(int *) * nodes);  
        for (j = 0; j < nodes; j++) {          
          array2[i][j] = (int *)malloc(sizeof(int) * nodes)
      for (k = 0; k < nodes; k++)
          array2[i][j][k] = i * j * k;
    
    
    for (i=0; i<iter; i++){
        for (j=0; j<nodes; j++){
          for (k=0; k<nodes; k++){
    	array2[i][j][k] = array1[j][k];    (//array 1 is 2D array )
    
    	printf("%d\t",array2[i][k][j])   
    return array2;
    then i pass the value of array 2 to the next function:

    Code:
    void Table(int , int ***array2, struct Vertex vert[size]);
    here only 1st matrix is read not the all.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm no expert on this, but you've got 3 calls to malloc(), and C has no guarantee that all three calls will be given contiguous addresses.

    I believe it was Laserlight who posted about how to force this, last week.

    My only suggestion would be to force malloc() to give you one contiguous block of memory, instead of the (probable) three disjointed blocks it's giving you now.

    Of course, you could assign pointers to the other two malloc addresses, and pass them over to your function, but that seems like a funky way of handling it.

    See if you can find that post by Laserlight, and give it a Google. Meanwhile, this will "bump" your thread up so it will be seen more readily by the experts.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    Finding indices efficiently

    In that thread, Salem describes on of many methods to force arrays to be contiguous in memory

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM