A linked list is a chain of nodes. Each node stores a value and a pointer to the next node, so the list grows and shrinks one node at a time without moving other elements. Unlike an array it has no random access, but inserting or deleting at a known position needs no shifting. This section covers nodes and links, creating and traversing lists, insertion, deletion, searching, reversing, doubly linked lists, and circular lists.
Draw the pointers.
Most linked-list bugs are pointer-order mistakes. Sketch boxes and arrows, and update new links before breaking old ones.
Path
Learning Path
Work through the stages in order, or jump to a topic from the index below (10 tutorials).
Overwriting the only pointer to the first node leaks the whole list.
null
Dereferencing NULL
p->next->data crashes at the end of the list. Test p->next first.
free
Freeing then reading
Save p->next before calling free(p).
Remember
Key Takeaways
Node: value plus next pointer.
End:NULL.
Ownership: free every node.
One line: A linked list is a chain of nodes.
Frequently Asked Questions
A linked list is a sequence of dynamically allocated nodes, each containing data and a pointer to the next node.
Use a linked list when you insert or delete often in the middle and do not need random access by index. Arrays are faster for indexed access and iteration.