Linked Lists
Last updated
Was this helpful?
Last updated
Was this helpful?
A linked list is a type of data structure made up of nodes:
You usually use a linked list for memory management reasons. The main difference between linked lists and arrays is dynamic memory allocation and memory overhead. With a linked list you can malloc and dealloc data as needed but each item in the list takes up extra space because it needs to contain a pointer to the next value.
Head Pointer
Mandatory pointer to the first value, if this is lost then the whole list is inaccessible
Head
The firsty node in the list
Tail Pointer
Optional but very useful for appending items to the end of the list
Tail
The last node in the list, tail->next must be a NULL pointer unless circly linked
'next' value
Mandatory struct member, my_node* type that points to next node
'prev' value
Optional struct member, my_node* type that points to previous node
'data' value
Madatory struct member, any type depending on data in question
Common operations on a linked list: insertion to a particular position, removal of a particular item, search for a particular item, iteration through with some sort of processing.