Implementations of different versions of sort routines.