3 ms·
But it's still a selection sort.
by mrcharles 17y ago
But it's still a selection sort.
- ajross 17y agoAnd thus one that works fine for many uses. Most "sorting" happens (at least when measuring "most" by line of code written) because you're about to display something to the user. Using a quadratic algorithm on the few hundred entries a person can actually interpret is hardly a problem. Pick the tool for the job (though, as pointed out elsewhere, that tool should probably be a library function). Algorithmic optimization isn't always as important as your textbooks tell you it is. If I were going to nitpick about this kind of exercise, I'd pick the insanity of compressing the whitespace (and symbol naming) of the thing, which a trivial deterministic tool can do. It represents no insight on the part of the author.
- icefox 17y agoWell sure, until you hit the case where two years down the road that 100 items is now 1,00,000 and if you had only used the built in function that does qsort... I would always choose a sorting function from a library over some hand grown thing (with no tests no doubt). They are too easy to make mistakes. Sorting functions are one of those things you get for free in [nearly] every language, writing a new one is usually just a waste of time.