Bubble Sort
Bubble sort is the one I reach for when I want to see a sort work. This is about the simplest version there is: two loops. For each slot i, it walks every value to the right and swaps in anything smaller, so by the end of that pass the smallest remaining value has settled into slot i. Do that for every slot, left to right, and the array comes out sorted, smallest to largest.
It’s slow. There’s no early exit and the inner loop even compares each slot with itself once, so it always does about n² comparisons no matter how the data starts — nobody’s sorting a million things with it. But it’s the clearest way I know to watch how comparisons and swaps stack up.
Variations
The Variant menu up top also has bubble sort’s classic cousins — the neighbor-swapping family, where each pass compares side-by-side pairs instead of one slot against the whole tail. Each runs on the same shuffle, so you can see what its twist buys you.
Cocktail shaker sweeps neighbors both ways, left to right and then back.
Comb sort keeps the same swap-the-bigger-one move, but it starts by comparing values far apart and closes the gap by about a third each pass until it’s back to 1 and it’s plain bubble again.
Gnome sort steps forward while each pair is in order, and the moment one isn’t, it swaps and backs up until the pair behind it is fine again before moving on.
Hit Play to watch it run, or use Next and Back to step one comparison at a time. Shuffle deals a fresh array, and the highlighted line shows you where the code is at each step. The Variant menu swaps in one of bubble sort’s close cousins on the same array, so you can watch them race the same data.