Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
/*REXX pgm sorts an array of integers (can be negative) using the count─sort algorithm.*/
|
||||
$= '1 3 6 2 7 13 20 12 21 11 22 10 23 9 24 8 25 43 62 42 63 41 18 42 17 43 16 44 15 45 14 46 79 113 78 114 77 39 78 38'
|
||||
#= words($); w= length(#); !.= 0 /* [↑] a list of some Recaman numbers.*/
|
||||
m= 1; LO= word($, #); HI= LO /*M: max width of any integer in $ list*/
|
||||
do j=1 for #; z= word($, j)+0; @.j= z; m= max(m, length(z) ) /*get from $ list*/
|
||||
!.z= !.z + 1; LO= min(LO, z); HI= max(HI, z) /*find LO and HI.*/
|
||||
end /*j*/
|
||||
/*W: max index width for the @. array.*/
|
||||
call show 'before sort: '; say copies('▓', 55) /*show the before array elements. */
|
||||
call countSort # /*sort a number of entries of @. array.*/
|
||||
call show ' after sort: ' /*show the after array elements. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
countSort: parse arg N; x= 1; do k=LO to HI; do x=x for !.k; @.x= k; end /*x*/
|
||||
end /*k*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: do s=1 for #; say right("element",20) right(s,w) arg(1) right(@.s,m); end; return
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* 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
|
||||
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<>''
|
||||
Parse Var alist a.i alist;
|
||||
lo=min(lo,a.i)
|
||||
hi=max(hi,a.i)
|
||||
End
|
||||
a.0=i-1
|
||||
|
||||
Call show 'before count_sort'
|
||||
Call count_sort
|
||||
Call show 'after count_sort'
|
||||
Exit
|
||||
|
||||
count_sort: procedure Expose a. lo hi
|
||||
t.=0
|
||||
do i=1 to a.0
|
||||
j=a.i
|
||||
t.j=t.j+1
|
||||
end
|
||||
k=1
|
||||
do i=lo to hi
|
||||
if t.i<>0 then Do
|
||||
do j=1 to t.i
|
||||
a.k=i
|
||||
k=k+1
|
||||
end
|
||||
end
|
||||
end
|
||||
Return
|
||||
|
||||
show: Procedure Expose a.
|
||||
Parse Arg head
|
||||
Say head
|
||||
ol=''
|
||||
Do i=1 To a.0
|
||||
ol=ol right(a.i,3)
|
||||
End
|
||||
Say ol
|
||||
Return
|
||||
|
||||
exit:
|
||||
Say arg(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue