Bubble Sort
Bubble sort is the one I reach for when I want to see a sort work. It walks the array left to right, looks at each pair of neighbors, and swaps them whenever the left one is bigger. The biggest value bubbles out to the end on every pass, so each pass can stop a slot earlier than the last. Go a whole pass without swapping anything and you’re done. It’s already sorted.
It’s slow. Worst case it’s on the order of n² comparisons, so nobody’s sorting a million things with it. But it’s the clearest way I know to watch how comparisons, swaps, and passes fit together.
Variations
These are all bubble sort with one thing changed. Pick one from the Variant menu above and it runs on the same shuffle, so you can see what the tweak actually buys you.
Cocktail shaker sweeps both ways instead of always left to right.
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.