Avoid infinite loops in pathological cases by double comparisons in sorting.