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.
1
A node is two things
struct Node { int data; Node* next; } — a value plus the address of the next node, allocated with new.
2
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.
3
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.
4
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.
5
Where you meet it
Print queues, playlists, undo chains, hash-table buckets and graph adjacency lists are linked nodes under the hood.
Meet the chain
A node is two things1struct Node { int data; Node* next; } — a value plus the address of the next node, allocated with new.
head is the list2One 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)3Two pointer writes put a new node in front — a vector pays O(n) to shift everything for the same job.
No random access4Reaching node #5 means hopping five times. v[5] on a vector is one address calculation; lists trade that for flexible linking.
Where you meet it5Print queues, playlists, undo chains, hash-table buckets and graph adjacency lists are linked nodes under the hood.
5 building blocks make up Meet the chain
Algorithm in motion
Insert at head & tail
New nodes jump the queue at the head — but appending at the tail means walking the whole chain first.
1 / 9
An empty list — head is nullptr. We will build it one node at a time.
How it works
The 3-move insert
Starting from 41 → 90, insert 23 at the head. The order of the two pointer writes is everything.
Watch it run
Walkthrough
Build a list with head inserts and print it — then cut one node out of the middle.
head = nullptr — an empty list. The head pointer is the only way in.
Memory
head= nullptr
Console
output appears as the program runs…
Step 1/16
Algorithm in motion
Traverse & delete
Deleting 23 needs the node before it — prev parks on 7, curr finds the victim, one write unlinks it.
head
7
node
23
node
41
node
90
node
null
1 / 9
The list reads 7 → 23 → 41 → 90 — goal: delete the node holding 23 without breaking the chain.
Challenge
Predict the output
Head inserts reverse arrival order — trace every pointer before you guess.
predict.cpp
1#include<iostream>
2usingnamespacestd;
3struct Node {int data; Node* next;};
4
5intmain(){
6 Node* head =nullptr;
7int vals[]={90,12,48};
8for(int i =0; i <3; i++) head =new Node{vals[i], head};
9int count =0;
10for(Node* p = head; p !=nullptr; p = p->next) count++;
11cout<< count <<" nodes, first is "<< head->data <<endl;
12return0;
13}
Your predicted output — one line per console line
Hint: Each new node is linked to head BEFORE head moves — so 90 lands first, 12 jumps in front of it, then 48 jumps in front of 12. Count every node until null.
Practice
Concept check
Click a term, then click its meaning to lock the pair.
8 conceptsTap a card to expand
?headdrops into place
?Nodedrops into place
?nullptrdrops into place
?head insertdrops into place
?tail insertdrops into place
?unlinkdrops into place
?no v[i]drops into place
?traversedrops into place
Recap
Key takeaways
Key takeaways6 takeaways
01
A node is data+ next: the chain is held together by addresses, not by memory position.
02
Link the new node to head BEFORE moving head — the reverse order orphans the rest of the list.
03
Insert at head is O(1); insert at tail is O(n) unless you also keep a tail pointer.
04
Deleting node X needs the node before it: prev->next= curr->next, then delete curr.
05
No random access — the k-th node costs k hops. Vectors buy O(1) indexing with contiguous memory.
06
Traverse with for (Node* p= head; p; p= p->next) — it is the only way to visit nodes.