Is it best to keep the head (double pointer) of a linked list inside or outside the structure for the linked list itself?
Asked
Active
Viewed 55 times
-1
-
1Why do you think that `head` of linked list is a double pointer? A `head` of a linked list is just a pointer of type _node_ of that list which point to the first node of the list. If you make it part of _node_ then every node will have its own `head` pointer. – H.S. Nov 16 '19 at 02:51
-
what is the `structure for the linked list` in your question? What does it contain? – Serge Nov 16 '19 at 03:14
1 Answers
0
Having a struct to contain the attributes of the linked list allows you to have multiple instances of a linked list at once.
That said, if the head is the only attribute of the linked list —i.e. if you don't maintain a tail or a count, and if you'd don't support per-list custom allocators and deallocators— then there's no point in using a struct. Well, using a struct would make it easier to add those features if you ever decide you need them.

ikegami
- 367,544
- 15
- 269
- 518