Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
/*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('▒', 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. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
bSort: procedure expose @.; parse arg n /*N: is the number of @ array elements.*/
|
||||
do m=n-1 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"
|
||||
@.3 = 'aleph [alef]' ; @.15= "mem"
|
||||
@.4 = 'beth [bet]' ; @.16= "nun"
|
||||
@.5 = 'gimel' ; @.17= "samekh"
|
||||
@.6 = 'daleth [dalet]' ; @.18= "ayin"
|
||||
@.7 = 'he' ; @.19= "pe"
|
||||
@.8 = 'waw [vav]' ; @.20= "sadhe [tsadi]"
|
||||
@.9 = 'zayin' ; @.21= "qoph [qof]"
|
||||
@.10= 'heth [het]' ; @.22= "resh"
|
||||
@.11= 'teth [tet]' ; @.23= "shin"
|
||||
@.12= 'yod' ; @.24= "taw [tav]"
|
||||
do #=1 until @.#==''; end; #=#-1 /*determine #elements in list; adjust #*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: do j=1 for #; say ' element' right(j,length(#)) arg(1)":" @.j; end; return
|
||||
|
|
@ -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 /*N: is the number of @ array elements.*/
|
||||
do m=n-1 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: h=min(N+N,1e5); w=length(h); do j=1 for N; @.j=random(h); end; return
|
||||
show: parse arg $; do k=1 for N; $=$ right(@.k, w); end; say $; return
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*REXX*/
|
||||
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
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*REXX program sorts an array (of any kind of numbers) using the bubble─sort algorithm.*/
|
||||
parse arg N seed . /*obtain optional size of array from CL*/
|
||||
if N=='' | N=="," then N=30 /*Not specified? Then use the default.*/
|
||||
if datatype(seed, 'W') then call random ,,seed /*An integer? Use the seed for RANDOM.*/
|
||||
call gen N /*generate the array elements (items). */
|
||||
call show 'before sort:' /*show the before array elements. */
|
||||
$$= $ /*keep "before" copy for after the sort*/
|
||||
call bSort N /*invoke the bubble sort with N items.*/
|
||||
say $$
|
||||
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: is the number of @ array elements.*/
|
||||
call disp /*show a snapshot of the unsorted array*/
|
||||
do m=#-1 by -1 until ok; ok=1 /*keep sorting the @ array until done.*/
|
||||
do j=1 for m; k=j+1
|
||||
if @.j>@.k then do; parse value @.j @.k 0 with @.k @.j ok
|
||||
end
|
||||
end /*j*/ /* [↑] swap 2 elements, flag as ¬done.*/
|
||||
call disp /*show snapshot of partially sorted @. */
|
||||
end /*m*/; return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
gen: do j=1 for N; @.j= j; end
|
||||
do k=1 for N; g= random(1,N); parse value @.k @.g with @.g @.k; end; return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: parse arg $; do k=1 for N; $=$ right(@.k, length(N)); end; say $; return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
disp: 'CLS'; $.= /*"CLS" is the command to clear screen.*/
|
||||
do e=1 for #; $.e= '│'overlay("☼", $.e, @.e); end /*e*/
|
||||
do s=# for # by -1; say $.s; end /*s*/
|
||||
say "└"copies('─', #) /*display the horizontal axis at bottom*/
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue