Jump to content

Sorting algorithms/Counting sort: Difference between revisions

added RPL
(added RPL)
 
Line 3,302:
return f
</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}}==
1,150

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.