Bubble sort is just fine if you're sure you'll only have a few items, or if it's likely that it might already be sorted, but it's still embarrassing admitting implementing it. Even Barack Obama knows that!
https://en.wikipedia.org/wiki/Bubble_sort#Performance
>The only significant advantage that bubble sort has over most other algorithms, even quicksort, but not insertion sort, is that the ability to detect that the list is sorted efficiently is built into the algorithm. When the list is already sorted (best-case), the complexity of bubble sort is only O(n). By contrast, most other algorithms, even those with better average-case complexity, perform their entire sorting process on the set and thus are more complex. However, not only does insertion sort share this advantage, but it also performs better on a list that is substantially sorted (having a small number of inversions). Additionally, if this behavior is desired, it can be trivially added to any other algorithm by checking the list before the algorithm runs.
>In popular culture: In 2007, former Google CEO Eric Schmidt asked then-presidential candidate Barack Obama during an interview about the best way to sort one million integers; Obama paused for a moment and replied "I think the bubble sort would be the wrong way to go."
Here's an implementation of bubble sort written in PostScript by Sam Leffler, renowned BSD/Lucasfilm/Pixar/SGI/Alias/Softimage/VMWare hacker, which he sent me and gave me permission to distribute in 1988, but which he was too embarrassed to sign his own name to, so he used the pseudonym "Bobo Leffler".
https://donhopkins.com/home/archive/psiber/cyber/bubblesort....
https://en.wikipedia.org/wiki/Samuel_J._Leffler
Also here's a PostScript heap sort by Owen Densmore of Sun, and a PostScript insertion sort by John Warnock of Adobe, both of whom used their real names:
https://donhopkins.com/home/archive/psiber/cyber/heapsort.ps
https://donhopkins.com/home/archive/psiber/cyber/insertion-s...