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

Discussion in 'C' started by Jose Francisco, Aug 23, 2007.

  1. Jose Francisco

    Jose Francisco New Member

    Joined:
    Aug 23, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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 :)
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     
  3. Jose Francisco

    Jose Francisco New Member

    Joined:
    Aug 23, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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?

    Do you meant it will be assigned automatically?

    Code:
    L->prev=L;
    Is that what you mean?

    Thank you for your time,
    Jose :)
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice