September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,18 +1,17 @@
/*REXX program sorts an array (of any kind of items) using the bubble─sort algorithm.*/
call gen /*generate the array elements (items).*/
call show 'before sort' /*show the before array elements. */
say copies('', 79) /*show a separator line (before/after).*/
call bubbleSort # /*invoke the bubble sort with # items.*/
say copies('', 70) /*show a separator line (before/after).*/
call bSort # /*invoke the bubble sort with # items.*/
call show ' after sort' /*show the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bubbleSort: procedure expose @.; parse arg n; m=n-1 /*N: number of array elements. */
do m=m for m by -1 until ok; ok=1 /*keep sorting array until done.*/
do j=1 for m; k=j+1; if @.j<=@.k then iterate /*Not out─of─order?*/
_=@.j; @.j=@.k; @.k=_; ok=0 /*swap 2 elements; flag as ¬done*/
end /*j*/
end /*m*/
return
bSort: procedure expose @.; parse arg n; m=n-1 /*N: is the number of @ array elements.*/
do m=m for m by -1 until ok; ok=1 /*keep sorting the @ array until done.*/
do j=1 for m; k=j+1; if @.j<=@.k then iterate /*elements in order? */
_=@.j; @.j=@.k; @.k=_; ok=0 /*swap two elements; flag as not done.*/
end /*j*/
end /*m*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: @.=; @.1 = '---letters of the Hebrew alphabet---' ; @.13= "kaph [kaf]"
@.2 = '====================================' ; @.14= "lamed"
@ -26,7 +25,7 @@ gen: @.=; @.1 = '---letters of the Hebrew alphabet---' ; @.13= "kaph
@.10= 'heth [het]' ; @.22= "resh"
@.11= 'teth [tet]' ; @.23= "shin"
@.12= 'yod' ; @.24= "taw [tav]"
do #=1 while @.#\==''; end; #=#-1 /*determine #elements in list; adjust #*/
do #=1 until @.#==''; end; #=#-1 /*determine #elements in list; adjust #*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: w=length(#); do j=1 for #; say 'element' right(j,w) arg(1)":" @.j; end; return
show: do j=1 for #; say ' element' right(j,length(#)) arg(1)":" @.j; end; return

View file

@ -0,0 +1,16 @@
/*REXX program sorts an array (of any kind of numbers) using the bubble─sort algorithm.*/
parse arg N .; if N=='' | N=="," then N=30 /*obtain optional size of array from CL*/
call gen N /*generate the array elements (items). */
call show 'before sort:' /*show the before array elements. */
call bSort N /*invoke the bubble sort with N items.*/
call show ' after sort:' /*show the after array elements. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
bSort: procedure expose @.; parse arg n; m=n-1 /*N: is the number of @ array elements.*/
do m=m for m by -1 until ok; ok=1 /*keep sorting the @ array until done.*/
do j=1 for m; k=j+1; if @.j>@.k then parse value @.j @.k 0 with @.k @.j ok
end /*j*/ /* [↑] swap 2 elements, flag as ¬done.*/
end /*m*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
gen: w=1; do j=1 for N; @.j=random(min(N+N,1e5)); w=max(w,length(@.j)); end; return
show: parse arg $; do k=1 for N; $=$ right(@.k, w); end; say $; return

View file

@ -0,0 +1,24 @@
Call random ,,1000
Do i=1 To 10
a.i=random(20)
End
a.0=i-1
Call show 'vorher '
Call bubble_sort
Call show 'nachher'
Exit
bubble_sort: Procedure Expose a.
Do Until no_more_swaps
no_more_swaps=1
Do i=1 To a.0-1
i1=i+1
if a.i > a.i1 Then Do
temp=a.i; a.i=a.i1; a.i1=temp
no_more_swaps=0
End
End
End
Return
show:
l=''; Do i=1 To a.0; l=l a.i; End; Say arg(1)':'l
Return