Thread: How to create double link list for 2 level hierarchy!!

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    45

    How to create double link list for 2 level hierarchy!!

    Hi

    I have to create a 2D link list with 2 level hierarchy

    some thing like that

    Code:
    head nodes level 1: 0                1                   2
                        /|\             /\                  /|\
    Sub node level 2:  0 1 2            0 1               0 1 2
    Real Data under    |
     each sub node:    |      
                       \
                         int **join=Null;
                         int unique = 0;
                         int col;
                         int ptr;
                         int *tmp_perm=Null;
                         int col_elem;
    I know how to deal with 1 level link list structure. But i don't know how to access, delete, nodes and sub nodes from this 2 level hierarchy. Can any one help me how to deal with it. Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,416
    Well, one possible way to model this is to have each of the first level nodes have child nodes, like how you might implement the nodes of a multiway tree.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    There could be a list class or structure with a head and tail pointer to node, used to access the first level list, and included as a member of in each of the nodes in the first level list to access the second level lists.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Why do you call it a 2D linked list?
    Is there a difference between this and a tree?

    Try to explain your original problem, you may end up with a better approach !

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    45
    I created the 2 structures for 2D link list. I am not good with pointers. Can u tell me how can i initialize and get elements from min_cost_candidate structure?

    like some thing
    min_cost_all_col[0] ->min_cost[1].unique;
    min_cost_all_col[0] ->min_cost[1].tmp_perm[2];
    min_cost_all_col[0] ->min_cost[1].join[2][3];
    Code:
    typedef struct min_cost_candidate {
    
    
      /*! Array that join the processes belongs to same group */
      int **join=Null;
      /*! Number of unique groups communicating in a column */
      int unique = 0;
      /*! Column No.*/
      int col;
      /*! Use to get starting index of column j in the structure */
      int ptr;
      /*! Process permutation ordering within column */
      int *tmp_perm=Null;
      /*! Number of processes in column */
      int col_elem;
    } min_cost_candidate;
    
    
    /*! structure storing details of all permutation orders 
    which have smallest cost function for all columns  */
    
    
    typedef struct min_cost_all_col {
      /*! pointer to  array of min_cost_candidate elements of size of smallest_indexes_array */
      min_cost_candidate *min_cost;
      /*! Pointer to next column */
      struct min_cost_all_col *next;
    } min_cost_all_col;
    
    min_cost_candidate *min_cost = (min_cost_candidate*)malloc(size *sizeof(min_cost_candidate));
    min_cost_all_col *current_min_cost_all, *new_min_cost_all;


    Quote Originally Posted by rcgldr View Post
    There could be a list class or structure with a head and tail pointer to node, used to access the first level list, and included as a member of in each of the nodes in the first level list to access the second level lists.
    Last edited by gevni; 06-12-2014 at 07:47 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double link list deletion gives heap error
    By sed_y in forum C Programming
    Replies: 5
    Last Post: 05-06-2011, 07:01 PM
  2. Replies: 6
    Last Post: 05-25-2010, 08:04 PM
  3. Taskbars; 'Cannot create top level child window'
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-18-2007, 06:41 AM
  4. Double Link List Swap function
    By kennny2004 in forum C++ Programming
    Replies: 1
    Last Post: 04-12-2006, 11:52 AM
  5. Create Link List for object
    By winsonlee in forum C++ Programming
    Replies: 6
    Last Post: 08-05-2004, 01:57 PM

Tags for this Thread