SysQSort for sorting on PalmOS – optimizations

I never really read the documentation for the built in quick sort function for Palm OS. The only thing I ever looked at was how to swallow the extra parameter for the function. If I had read the documentation properly I would have noticed that it possesses several very handy optimizations that come (mostly) for free. The first is that it automatically uses an insertion sort if the number of records are ‘low’. This is very handy, as it means you don’t need to decided to use one algorithm over the other. It also swaps to an insertion sort if at a point in the sorting it discovers that the stack is about to be consumed completely, which means no mysterious application crashes due to the recursive nature of the quick sort.
The only real problem with it is that it, like all other versions of quicksort is that it’s unstable. If two items have the same key then they may appear on the output in a different order than they were input. Not a big pain really.