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

1. ## 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. 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.

3. 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. 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. 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;```

Originally Posted by rcgldr
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.