Sorting algorithms/Counting sort: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
(added RPL) |
||
Line 3,302: | Line 3,302: | ||
return f |
return f |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|RPL}}== |
|||
{{works with|RPL|HP-49C}} |
|||
« { } → in bins |
|||
« in « MIN » STREAM DUP |
|||
in « MAX » STREAM |
|||
'''FOR''' j |
|||
'bins' |
|||
'''IF''' in j POS |
|||
'''THEN''' 0 in + « j == + » STREAM |
|||
'''ELSE''' 0 '''END''' |
|||
STO+ |
|||
'''NEXT''' |
|||
{ } |
|||
1 bins SIZE '''FOR''' j |
|||
OVER j + 1 - 'bins' j GET NDUPN →LIST + |
|||
'''NEXT''' NIP |
|||
» '<span style="color:blue">CSORT</span>' STO |
|||
{ -5 1 0 5 7 5 1 2 -3 1 } <span style="color:blue">CSORT</span> |
|||
{{out}} |
|||
<pre> |
|||
1: { -5 -3 0 1 1 1 2 5 5 7 } |
|||
</pre> |
|||
Counting sort is 17 times slower than the <code>SORT</code> built-in function on an HP-50g. |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |