Singly Linked Lists

Lesson 9 of 20

Build a chain of nodes with O(1) head inserts, walk to the tail, then unlink 23 mid-list — every move is a pointer write.

The big picture

Meet the chain

A linked list stores each element in its own node, glued to the next one by a pointer — the chain is held together by addresses, not by memory position.

A node is two things

struct Node { int data; Node* next; } — a value plus the address of the next node, allocated with new.

head is the list

One pointer to the first node is the only handle. The last node’s next is nullptr — the official end-of-chain sign.

Head insert is O(1)

Two pointer writes put a new node in front — a vector pays O(n) to shift everything for the same job.

No random access

Reaching node #5 means hopping five times. v[5] on a vector is one address calculation; lists trade that for flexible linking.

Where you meet it

Print queues, playlists, undo chains, hash-table buckets and graph adjacency lists are linked nodes under the hood.