2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,35 +1,25 @@
/*REXX program to sort an integer array L [elements start at zero]. */
highItem=19 /*define 0 ──► 19 elements. */
widthH=length(highItem) /*width of biggest element number*/
widthL=0 /*width of largest element value.*/
do k=0 to highItem /*populate the array with stuff. */
L.k=2*k + (k * -1**k) /*kinda generate randomish nums. */
if L.k==0 then L.k=-100-k /*if zero, make a negative number*/
widthL=max(widthL,length(L.k)) /*compute maximum width so far. */
end /*k*/
call showL 'before sort' /*show the before array elements.*/
call stoogeSort 0,highItem /*invoke the Stooge Sort. */
call showL ' after sort' /*show the after array elements.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SHOWL subroutine────────────────────*/
showL: sepLength=22+widthH+widthL /*compute separator width. */
say copies('-',sepLength) /*show the 1st separator line. */
do j=0 to highItem
say 'element' right(j,widthH) arg(1)":" right(L.j,widthL)
end /*j*/
say copies('=', sepLength) /*show the 2nd separator line. */
return
/*──────────────────────────────────STOOGESORT subroutine───────────────*/
stoogeSort: procedure expose L.; parse arg i,j /*sort from I ──> J.*/
if L.j<L.i then parse value L.i L.j with L.j L.i /*swap L.i with L.j*/
if j-i>1 then do
t=(j-i+1) % 3 /* % is REXX integer division. */
call stoogesort i , j-t
call stoogesort i+t, j
call stoogesort i , j-t
end
return
/*REXX program sorts an integer array @. [the first element starts at index zero].*/
parse arg N . /*obtain an optional argument from C.L.*/
if N=='' | N=="," then N=19 /*Not specified? Then use the default.*/
wV=0 /*width of the largest value, so far.*/
do k=0 to N; @.k=k*2 + k*-1**k /*generate some kinda scattered numbers*/
if @.k//7==0 then @.k= -100 -k /*Multiple of 7? Then make a negative#*/
wV=max(wV, length(@.k)) /*find maximum width of values, so far.*/
end /*k*/ /* [↑] // is REXX division remainder.*/
wN=length(N) /*width of the largest element number.*/
call show 'before sort' /*show the before array elements. */
say copies('', wN+wV+ 50) /*show a separator line (between shows)*/
call stoogeSort 0, N /*invoke the Stooge Sort. */
call show ' after sort' /*show the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do j=0 to N; say right('element',22) right(j,wN) arg(1)":" right(@.j,wV); end;return
/*──────────────────────────────────────────────────────────────────────────────────────*/
stoogeSort: procedure expose @.; parse arg i,j /*sort from I ───► J. */
if @.j<@.i then parse value @.i @.j with @.j @.i /*swap @.i with @.j */
if j-i>1 then do; t=(j-i+1) % 3 /*%: integer division.*/
call stoogeSort i , j-t /*invoke recursively. */
call stoogeSort i+t, j /* " " */
call stoogeSort i , j-t /* " " */
end
return