A sort function that can be used to sort in various ways.