Sort using a custom comparator: Difference between revisions
Content deleted Content added
→{{header|Smalltalk}}: switched < for > |
m Changed over to works with template |
||
Line 1:
{{task}}Sort an array (or list) of strings in order of descending length, and in ascending lexicographic order for strings of equal length.
▲Sort an array (or list) of strings in order of descending length, and in ascending lexicographic order for strings of equal length. Use a sorting facility provided by the language/library, combined with your own callback comparison function.
'''Note:''' Lexicographic order is case-insensitive.
=={{header|Ada}}==
===Comparator_Package.ads===
package Comparator_Package is
Line 105 ⟶ 103:
=={{header|C}}==
'''Platform:''' [[BSD]]
#include <stdlib.h>
Line 127 ⟶ 124:
=={{header|C++}}==
#include <algorithm>
#include <string>
Line 183 ⟶ 179:
=={{header|D}}==
{{libheader|Tango}}
<pre>module customsort ;
Line 239 ⟶ 234:
=={{header|Haskell}}==
{{works with|GHC}}
import List
import Char
Line 274 ⟶ 269:
=={{header|Java}}==
{{works with|Java|1.5+}}
import java.util.Comparator;
import java.util.Arrays;
Line 336 ⟶ 330:
=={{header|Perl}}==
{{works with|Perl|5.8.6}}
sub mycmp { length $b <=> length $a or lc $a cmp lc $b }
Line 343 ⟶ 337:
=={{header|PHP}}==
<?php
function mycmp($s1, $s2)
Line 380 ⟶ 374:
=={{header|Python}}==
{{works with|Python|2.5}}
<pre>
def mycmp(s1, s2):
|