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

Jose Francisco's Avatar, Join Date: Aug 2007
Newbie Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
Jose Francisco's Avatar, Join Date: Aug 2007
Newbie Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.