← CS 302 Home

Bubble Sort — Adjacent Swaps with Early Termination

Compare adjacent pairs left to right. Swap if out of order. Largest bubbles to the end each pass.
Boolean flag: if a pass has zero swaps, stop early — already sorted!

Unsorted
Swapped
Compared, no swap
Sorted (final position)