Sort using a custom comparator: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
|||
Line 2,135: | Line 2,135: | ||
|strings|sample|sorted|Here|some|are|be|to| |
|strings|sample|sorted|Here|some|are|be|to| |
||
+-------+------+------+----+----+---+--+--+</lang> |
+-------+------+------+----+----+---+--+--+</lang> |
||
Generally speaking, J uses the concept of sorting against a normalized content (which is what <code>length_and_lex</code> provided in the above example). This eliminates a class of errors (which might be conceptualized by using a custom comparator which generates a random number: order would be non-deterministic and sorted order would depend on details of the sorting algorithm) and supports O(n) sorting algorithms such as bin sort (which cannot use comparators). |
|||
=={{header|Java}}== |
=={{header|Java}}== |