Every linked list operation is built from the same three moves: walk with a pointer, save the arrow you're about to change, and re-point an arrow. This lesson builds the everyday operations from those moves, in four languages.
Most problems hand you a list, but for testing you'll often want to build one. The trick is a dummy node in front: it gives the loop a place to attach the first real node, so there's no special case for an empty list.
Members only · free account
The rest of this lesson, with 6 more sections, 4 drawings, 2 dry-run simulators and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson