I've got a question...we all know double arrays a[100][100], but how to change it into linked list or like" linked list to linked list" that we could transfer data like in a double array a[j]?
12345....
2
3
.
.
.
Ideas?
Graph>weighted>minimal tree>neighborhood list(yes normally matrix, but i need LIST) ???

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by John A

You'll want to create a structure that is designed like a binary tree. One pointer points to the next row in the matrix, and the other points to the next element in the row. So your structure would look something like:

``````struct matrix
{
int data;
struct matrix *next;
struct matrix *next_row;
};``````

Depending on how you need to access your data, you may have to modify the number of pointers you use in the structure and what they point to. For example, if you're going back and forth a lot, you may want to make a doubly linked list, which would require four pointers instead of two. You may also want `next_row` to point to the nth element in the next row, instead of the first.

Cool, but how do you imagine this in list:
d=a[12];???

>Cool, but how do you imagine this in list:
>d=a[12];???

If you're trying to convert a two dimensional array into a one dimensional array (that's what I'm guessing you're trying to say -- your wording is very poor), then create a couple of nested loops and do the appropriate math inside there.

``````for (x = 0; x < length_of_x; x++)
{
for (y = 0; y < length_of_y; y++)
{
my_1d_array[ (length_of_y * x) + y ] = my_2d_array[x][y];
}
}``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.