Advertisement

Linked Lists

Started by August 25, 2001 10:30 AM
2 comments, last by steveharper101 23 years, 5 months ago
could someone explain to me how this works? I have never used link list''s before. It''s taken from the SimpEngine. if (parentNode->childNode) { prevNode = parentNode->childNode->prevNode; nextNode = parentNode->childNode; parentNode->childNode->prevNode->nextNode = this; parentNode->childNode->prevNode = this; } ~Steve~
Here''s the idea of linked lists...

          -----    -----    -----    -----    -----    -----        |   |--->|   |--->|   |--->|   |--->|   |--->|   |--->NULL        |   |    |   |    |   |    |   |    |   |    |   |NULL<---|   |<---|   |<---|   |<---|   |<---|   |<---|   |        -----    -----    -----    -----    -----    -----  


Since you have a "this", this is obviously a function belonging to a class, and it looks like that "parentNode" is a parameter to the function.

Now in this example, a simple node looks like this:

            -----          |   |--->prevNode  |   |  childNode      <---|   |          -----  


That is to say, whenever you access "childNode" of any node, you''re jumping forward in the linked list, and "prevNode" jumps back one node in the list.

So to figure out exactly what it does, draw out the list of what all the pointers refer to, and then draw out all of the things done to the list.

Hope this helps!

~ Dragonus
Advertisement
Instead of trying to incorporate your own linked lists, why not use C++''s standard template library...
It has its own doubly-linked list class
just include
Or even better, use the STL vectors...

Just an idea...
Use it, don''t use it
I don''t like lists simply because of those blasted iterators. I never did figure them out enough to be comfortable with them.

is nice though, however, for some strange reason, on the project I''m working on (don''t ask me why), I get linker errors whenever I try to load that in, as well as half of the other std libraries... grrrrrr...

~ Dragonus

This topic is closed to new replies.

Advertisement