Page 1 of 1

multidimesional double linked lists (c++)

Posted: Thu Aug 16, 2007 2:19 am
by Zacariaz
When i am in the process on learning something new i usually give myself some challences, and ive done that with the subject of linket lists too.
However when working with multidimensional double linket lists i get into trouble.
I fully understand how they work and can easily make them manually, but it is very timeconsuming and doesnt really make sence in the learning process.
Of course it has to be automated, classes or functions or whatever, but i cant figure out how and it enoys the hell outa me.

The original challence was to create a kind of static wrapped grid with no root, center, whatever. The concept is easy and when the list is first created it is easy to move around within the bounderies, but creating it is a problem for me.

Ive tryed googling over and over again, and i find that people are actually doing this, dont quite know why, but not much explaining is avalible.

Any expert oppinion?

again, i have no problem with the concept of the linked list it self, it is the structuring that is a problem.


(I realise that this might sound kinda stupid and if that is infact the case, please just disregard it)

Re: multidimesional double linked lists (c++)

Posted: Thu Aug 16, 2007 3:03 am
by AndrewAPrice
If I were to have a multi dimensional double linked list, I'd have a previous/next pointer for each dimension, e.g.:

Code: Select all

struct MyLinkedList
{
      MyLinkedList *NextA; // dimension 1
      MyLinkedList *PreviousA;

      MyLinkedList *NextB; // dimension 2
      MyLinkedList *PreviousB;

      // add additional dimensions here
}
If it was a 2D array, it would be simpler to think of it in terms of a table or grid:

Code: Select all

struct MyLinkedList
{
      MyLinkedList *left; // dimension 1
      MyLinkedList *right;

      MyLinkedList *up; // dimension 2
      MyLinkedList *down;
}
But, if you insert/remove an item from the list, you're going to have to change every the pointers of every touching element so all the cells in our imaginary multi-dimensional table match up.

To make it slightly more complicated, you could have a double linked list with infinite dimensions. Each linked list object could store it's next/previous pointers in a separate linked list. So each object could have an independent number of dimensions. Let's make it even more complicated by making the linked list's linked list of pointers also infinitely dimensional. I should create a working model, write a paper on it, and name it a "recursively infinite-dimensional double linked list" and have my name in every programming book to be published!

Posted: Thu Aug 16, 2007 3:25 am
by Zacariaz
sarkasm doesnt work very well in writing, but thanks for the answer anyway.