C: Header Cell/Node in a Double Circularly Linkeded List

Newbie Member
23Aug2007,08:21   #1
Jose Francisco's Avatar
Hey guys!

I need some assistance in creating my header node or cell in a double circularly linked list. I have come up with the single linked list header node:

Code:
list_ptr createHeader (void){
 list_ptr L;
 L = (list_ptr) malloc(sizeof(list));
 L->next = NULL;
 return L;
}
However, I'm having difficulty in coding the header previous, which in fact would instantly point to the last node in my double circularly linked list. How do I go about adding that code to my createHeader function?

Is it as simple as stating the following:
Code:
L->prev = NULL;
Am I missing something?

Thanks again!
Regards,
Jose
Go4Expert Founder
23Aug2007,08:32   #2
shabbir's Avatar
It should be assigned when you have the second node in question or you can point to the head node itself whichever is useful to you. I would prefer assigning it to the head node.
Newbie Member
24Aug2007,19:57   #3
Jose Francisco's Avatar
Hey shabbir!

Thanks for the prompt reply. I am not really understanding your reply. How do we go about implementing that in my createHeader function?

Quote:
It should be assigned when you have the second node in question
Do you meant it will be assigned automatically?

Quote:
you can point to the head node itself
Code:
L->prev=L;
Is that what you mean?

Thank you for your time,
Jose
Go4Expert Founder
24Aug2007,22:12   #4
shabbir's Avatar
For the second node It will not be automatic but you need to be doing that but the second option I was saying is what you have understood.