Entry in a Circular Linked List
Hey Folks,
I was reading an old article yesterday posted here about Linked Lists and remember the writer saying that if you lose the head of your linked list then you lose your entry point into the list. Then how do you gain access into a circular linked list where the end points to the head? Do you just choose the head and keep it marked? Thanks in advance.
~Wave
Well, just because the last item links back to the first doesn''t mean that you can''t also keep a pointer to that first element of the list if you want one. But since you''re using a circular list, you may not need a reference that consistently points to the same object at all times. You''d just use the pointer to the current item as your reference to the list. So if you have, for example, an
LLITEM *lpLLItem;
then when you create your list of LLITEM structures, you''d initialize that one pointer to point to the first object you add to the list. That pointer will change as you work with other objects in the list, but that doesn''t matter if the list is circular. You don''t need a static pointer to the list since you can do this:
lpLLItem = lpLLItem->lpNext;
for all eternity if you want to in a circular list. I know this isn''t a particularly great explanation but hopefully it helps at least a little bit.
-Ironblayde
Aeon Software
Down with Tiberia!![](http://www.aeon-software.com/misc/notiberia.gif)
"All your women are belong to me." - Nekrophidius
LLITEM *lpLLItem;
then when you create your list of LLITEM structures, you''d initialize that one pointer to point to the first object you add to the list. That pointer will change as you work with other objects in the list, but that doesn''t matter if the list is circular. You don''t need a static pointer to the list since you can do this:
lpLLItem = lpLLItem->lpNext;
for all eternity if you want to in a circular list. I know this isn''t a particularly great explanation but hopefully it helps at least a little bit.
![](smile.gif)
-Ironblayde
Aeon Software
![](http://www.aeon-software.com/misc/notiberia.gif)
![](http://www.aeon-software.com/misc/notiberia.gif)
"All your women are belong to me." - Nekrophidius
"Your superior intellect is no match for our puny weapons!"
It isn''t as important which one you point to as it is that you point to at least one. You have to have a pointer to one or you have no way to access the list. Where is it? Who knows. Generally your application is going to say one is more important to point at than the rest like the next one to be accessed.
Keys to success: Ability, ambition and opportunity.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement