How do you do it?
by Raymond Chen
From the article:
I’ve noted in the past that a sort comparison function must follow certain rules, and if you violate those rules, very strange things happen. So what are some patterns for writing sort comparison functions that don’t break the rules?
Most of the time, sorting can be reduced to key comparison: From each element being sorted, you generate a sort key, and those sort keys are compared against each other...