How to implement a linked list in C?

后端 未结 14 860
予麋鹿
予麋鹿 2020-12-06 02:49

I am creating a linked list as in the previous question I asked. I have found that the best way to develop the linked list is to have the head and tail in another structure.

14条回答
  •  天命终不由人
    2020-12-06 03:25

    Arguably you want your list data structure to be external to the data that it stores.

    Say you have:

    struct Whatever
    {
       int x_;
    }
    

    Then your list structure would look like this:

    struct Whatever_Node
    {
       Whatever_Node* next_
       Whatever* data_
    }
    

    Ryan Oberoi commented similarly, but w/o example.

提交回复
热议问题