5 ms·
The sort function has no reason to ask for all three comparisons. Rather, it can ask for two comparisons and act according to the results (e.g. it learns that
by devit 3y ago
The sort function has no reason to ask for all three comparisons.
Rather, it can ask for two comparisons and act according to the results (e.g. it learns that 1 < 2 and 2 < 3 and returns [1, 2, 3]).
This makes the output unspecified in general, but it will be consistent with the information received and the calls made even if the comparator doesn't form an ordering, which is what one would expect.