multidimesional double linked lists (c++)

Programming, for all ages and all languages.
Post Reply
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

multidimesional double linked lists (c++)

Post 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)
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: multidimesional double linked lists (c++)

Post 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!
My OS is Perception.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

sarkasm doesnt work very well in writing, but thanks for the answer anyway.
Post Reply