Re:Programmers can’t write algorithms without help
by dickeytk on Monday November 04, 2019 @04:33PM
(#21446736)
Fair point. Perhaps it is harder than I thought without looking anything up or testing? At least to get the canonical version written down.
Re:Programmers can’t write algorithms without help
by eesmith on Monday November 04, 2019 @10:40PM
(#21449386)
I think it's that "bubble sort" has come to mean "a simple O(N²) sort implementation", of which there are many. But the selection sort just feels more natural than the actual bubble sort. At the very least, selection sort doesn't get my face to scrunch up in a scowl at all those memory movements.
More importantly, what you wrote is a selection sort, not a bubble sort!
A bubble sort swaps neighboring terms. Eg, if I interpret the code in 2.1 of https://users.cs.duke.edu/~ola/bubble/bubble.html correctly, the 'definitive' version is: