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) ???

Recommended Answers

All 3 Replies

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];
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.