Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,32 @@
|
|||
/*REXX program sorts an array using the count-sort algorithm. */
|
||||
call gen@ /*generate the array elements. */
|
||||
call show@ 'before sort' /*show the before array elements.*/
|
||||
call countSort # /*sort N entries of the @. array.*/
|
||||
call show@ ' after sort' /*show the after array elements.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────COUNTSORT subroutine────────────────*/
|
||||
countSort: procedure expose @.; parse arg N; h=@.1; L=h
|
||||
|
||||
do i=2 to N; L=min(L,@.i); h=max(h,@.i); end /*i*/
|
||||
|
||||
_.=0; do j=1 for N; x=@.j; _.x=_.x+1; end /*j*/
|
||||
|
||||
x=1; do k=L to h; if _.k\==0 then do x=x for _.k
|
||||
@.x=k
|
||||
end /*x*/
|
||||
end /*k*/
|
||||
return
|
||||
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
|
||||
gen@: $=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($)
|
||||
do j=1 for # /* [↓] assign 40 Recaman numbers.*/
|
||||
@.j=word($,j) /*assign a Recaman # from a list.*/
|
||||
end /*j*/
|
||||
return
|
||||
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
|
||||
show@: do s=1 for #
|
||||
say left('',9) "element" right(s,length(#)) arg(1)': ' @.s
|
||||
end /*s*/
|
||||
|
||||
say copies('─',50) /*show a pretty separator line. */
|
||||
return
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* 13.07.2014 Walter Pachl translated from PL/I
|
||||
*--------------------------------------------------------------------*/
|
||||
alist='999 888 777 1 5 13 15 17 19 21 5'
|
||||
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
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*REXX program sorts an array using the count-sort method. */
|
||||
call gen@ /*generate the array elements. */
|
||||
call show@ 'before sort' /*show the before array elements.*/
|
||||
call countSort N /*sort N entries of the @. array.*/
|
||||
call show@ ' after sort' /*show the after array elements.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────countSort subroutine────────────────*/
|
||||
countSort: procedure expose @.; parse arg N; h=@.1; L=h
|
||||
|
||||
do i=2 to N; L=min(L,@.i); h=max(h,@.i)
|
||||
end /*i*/
|
||||
|
||||
_.=0; do j=1 for N; x=@.j; _.x=_.x+1
|
||||
end /*j*/
|
||||
|
||||
#=1; do k=L to h; if _.k\==0 then do #=# for _.k
|
||||
@.#=k
|
||||
end /*#*/
|
||||
end /*k*/
|
||||
return
|
||||
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
|
||||
gen@: @.= /*assign 40 Recaman numbers. */
|
||||
@.1 = 1 ; @.9 = 21 ; @.17= 25 ; @.25= 17 ; @.33= 79
|
||||
@.2 = 3 ; @.10= 11 ; @.18= 43 ; @.26= 43 ; @.34= 113
|
||||
@.3 = 6 ; @.11= 22 ; @.19= 62 ; @.27= 16 ; @.35= 78
|
||||
@.4 = 2 ; @.12= 10 ; @.20= 42 ; @.28= 44 ; @.36= 114
|
||||
@.5 = 7 ; @.13= 23 ; @.21= 63 ; @.29= 15 ; @.37= 77
|
||||
@.6 = 13 ; @.14= 9 ; @.22= 41 ; @.30= 45 ; @.38= 39
|
||||
@.7 = 20 ; @.15= 24 ; @.23= 18 ; @.31= 14 ; @.39= 78
|
||||
@.8 = 12 ; @.16= 8 ; @.24= 42 ; @.32= 46 ; @.40= 38
|
||||
|
||||
do N=1 while @.N\==''; end /*determine the number of entries*/
|
||||
N=N-1 /*adjust highItem slightly. */
|
||||
return
|
||||
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
|
||||
show@: widthH=length(N) /*max width of any element number*/
|
||||
pad=left('',9); do s=1 for N
|
||||
say pad 'element' right(s,widthH) arg(1)": " @.s
|
||||
end /*s*/
|
||||
say copies('─',40) /*show a pretty separator line. */
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue