Sorting algorithms/Counting sort: Difference between revisions

→‎version 2: Take care of empty list
Tag: Made through Tor
(→‎version 2: Take care of empty list)
Line 3,160:
===version 2===
 
{{improve|REXX| <br> This code will fail when &nbsp; '''alist''' &nbsp; is either null or just has one element. <br>
<br> The inclusion of a semi-colon serves no purpose. <br>
<br> If any number is greater than 999 or less than -99, &nbsp; it is not listed correctly. <br><br>
<br> For a list of: <br>
<br> 1 &nbsp; 5 &nbsp; +99 &nbsp; 5 &nbsp; -14 <br>
<br> the number &nbsp; '''-14''' &nbsp; shows up <u>twice</u>. <br><br>}}
 
{{trans|PL/I}}
<syntaxhighlight lang="rexx">/* REXX ---------------------------------------------------------------
* 13.07.2014 Walter Pachl translated from PL/I
* 27.05.2023 Walter Pachl take care of bad lists
*--------------------------------------------------------------------*/
Parse Arg alist
alist='999 888 777 1 5 13 15 17 19 21 5'
If alist='*' Then
alist='999 888 777 1 5 13 15 17 19 21 5'
Select
When alist='' Then Call exit 'List is empty'
When words(alist)=1 Then Call exit 'List has only one element:' alist
Otherwise Nop
End
Parse Var alist lo hi .
Do i=1 By 1 While alist<>''
Line 3,210 ⟶ 3,212:
End
Say ol
Return</syntaxhighlight>
 
exit:
Say arg(1)
</syntaxhighlight>
'''Output:'''
<pre>before count_sort
2,295

edits