Sorting algorithms/Counting sort: Difference between revisions
Content added Content deleted
Deadmarshal (talk | contribs) Tag: Made through Tor |
Walterpachl (talk | contribs) (→version 2: Take care of empty list) |
||
Line 3,160: | Line 3,160: | ||
===version 2=== |
===version 2=== |
||
{{improve|REXX| <br> This code will fail when '''alist''' 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, it is not listed correctly. <br><br> |
|||
<br> For a list of: <br> |
|||
<br> 1 5 +99 5 -14 <br> |
|||
<br> the number '''-14''' shows up <u>twice</u>. <br><br>}} |
|||
{{trans|PL/I}} |
{{trans|PL/I}} |
||
<syntaxhighlight lang="rexx">/* REXX --------------------------------------------------------------- |
<syntaxhighlight lang="rexx">/* REXX --------------------------------------------------------------- |
||
* 13.07.2014 Walter Pachl translated from PL/I |
* 13.07.2014 Walter Pachl translated from PL/I |
||
* 27.05.2023 Walter Pachl take care of bad lists |
|||
*--------------------------------------------------------------------*/ |
*--------------------------------------------------------------------*/ |
||
Parse Arg alist |
|||
⚫ | |||
If alist='*' Then |
|||
⚫ | |||
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 . |
Parse Var alist lo hi . |
||
Do i=1 By 1 While alist<>'' |
Do i=1 By 1 While alist<>'' |
||
Line 3,210: | Line 3,212: | ||
End |
End |
||
Say ol |
Say ol |
||
Return |
Return |
||
exit: |
|||
Say arg(1) |
|||
</syntaxhighlight> |
|||
'''Output:''' |
'''Output:''' |
||
<pre>before count_sort |
<pre>before count_sort |