The comprehension of table. Sort's comparison function is not in place, and the result hurts me. t
This is the case in the Lua 5.1 manual:
Table. Sort (Table [, comp])
Sorts table elements in a given order, in-place, from table [1] to table [N], where N is the length of the table. if comp is given, then it must be a function that includes es two table elements, and returns true when the first is less than the second (so that not comp (A [I + 1], a [I]) will be true after the sort ). if comp is not given, then the standard Lua operator <is used instead.
The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort.
Returns true when the first isLessThe second
What should I return if the two parameters are equal? False!
The key is this. False must be returned; otherwise, the sorting result is incorrect.