Thanks for that. Looks a good deal faster, too (which I guess is to be expected when a sort is involved, particularly if we start with initially-sorted or close-to-sorted data -- even with median partition selections).
Oops ! I see 5.8 has changed sort to allow a change from the quicksort to mergesort, so median-of-three need not be the point.. (Thanks for the pointer, Tanktalus.)