All lessonsOpen Open Open Open Open
3. Linked Lists
Classic list algorithms
0 of 5 activities0%
Reading 1
Patterns you will reuse
Reverse: iterate with prev, cur, nextptr rewiring.
Middle: slow moves one step, fast moves two; when fast ends, slow is mid.
Cycle detection (Floyd): slow and fast; if they meet, there is a cycle.
These show up constantly in interviews.
Node* slow=head, *fast=head;
while (fast && fast->next) {
slow=slow->next;
fast=fast->next->next;
}Check 2
Middle trick
Slow/fast pointers find the middle because
Fill in 3
Cycle name
Try it 4
Reverse iterative
Reverse 1-2-3.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Print reversed values
Read n and n ints into an array (simulating a list). Print them in reverse order separated by spaces.
main.cpp
Loading editor…