Reference implementation of various sorting methods.