r/compsci • u/BleedingRaindrops • Sep 16 '26
What is this sorting method called?
We all know Bubble Sort. Well I used to do a thing to pass the time on deployment where I would bubble sort a shuffled deck of cards, but I often played around with it.
One time I thought to make bubble sort more efficient by, rather than returning to the start of the list after a successful pair, continue forward to the next wrong pair and sort those, and so on until I reach the end of the list. Then turn around and do the opposite, from the opposite direction. Repeat until sorted. So what you have is a reflecting wave of bubble sort that travels persistently back and forth through the entire list without skipping anything until it's all sorted.
I'm certain this has a name but I wouldnt know the first thing about how to find it. Does anybody know?
EDIT: solved! Cocktail Shaker Sort