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. Use a sorting facility provided by the language/library, combined with your own callback comparison function.
{{task}}
 
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}}==
'''Compiler:'''[[GNAT]]{{works with|GNAT|GPL 2006}}
===Comparator_Package.ads===
package Comparator_Package is
Line 105 ⟶ 103:
 
=={{header|C}}==
'''Compiler:'''{{works [[with|gcc]] |4.0.1}}
 
'''Platform:''' [[BSD]]
#include <stdlib.h>
Line 127 ⟶ 124:
 
=={{header|C++}}==
'''Compiler:'''{{works [[with|g++]] |4.1.2}}
 
#include <algorithm>
#include <string>
Line 183 ⟶ 179:
 
=={{header|D}}==
'''Compiler:'''{{works [[with|D]] - |DMD 1.026 }}
 
{{libheader|Tango}}
<pre>module customsort ;
Line 239 ⟶ 234:
 
=={{header|Haskell}}==
{{works with|GHC}}
'''Interpreter:''' [[GHC|GHCi]]
import List
import Char
Line 274 ⟶ 269:
 
=={{header|Java}}==
{{works with|Java|1.5+}}
J2SE 5.0:
 
import java.util.Comparator;
import java.util.Arrays;
Line 336 ⟶ 330:
 
=={{header|Perl}}==
{{works with|Perl|5.8.6}}
'''Interpreter:''' [[perl]] 5.8.6
sub mycmp { length $b <=> length $a or lc $a cmp lc $b }
Line 343 ⟶ 337:
 
=={{header|PHP}}==
'''Interpreter:'''{{works with|PHP |4.4.4 CLI}}
<?php
function mycmp($s1, $s2)
Line 380 ⟶ 374:
 
=={{header|Python}}==
{{works with|Python|2.5}}
'''Interpreter''': 2.5
<pre>
def mycmp(s1, s2):