Codele / Data structures
Linked lists
A treasure hunt: each stop holds a prize and a note that says where the next stop is. That chain of notes is a linked list.
- In a linked list each item (a node) holds its value and a note saying where the next node is.
- The first node is the head. You only keep the head; every other node is reached by following notes.
- Finding something means walking from the head, one stop at a time. You cannot jump to stop 5.
- Inserting in the middle changes only two notes. No item has to shift, unlike an array.
- Trade: once you are at the spot, a linked list inserts fast but searches slowly. Arrays read fast but insert slowly.
Loading the playable lesson…