Linked lists - single or double pointer to the head

前端 未结 3 1810
暖寄归人
暖寄归人 2021-01-16 09:57

We are given a task and a struct of linked list:

typedef struct dlistint_s
{
    int n;
    struct dlistint_s *prev;
    struct dlistint_s *next;
} dlistint_         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-16 10:27

    Because if you are using dlistint_t *head variable instead of using dlistint_t **head variable in function parameter then, changes made in variable head in function dlistint_t *add_dnodeint(dlistint_t **head, const int n); will be local to this method. Since you are using Node* so changes done in variable head is local to that function. If you want to reflect these changes even after function call(which you obviously wants to) then use dlistint_t **head.

提交回复
热议问题