Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
/*REXX program sorts an array using the gnome sort algorithm (elements contain blanks). */
|
||||
call gen /*generate the @ stemmed array. */
|
||||
call show 'before sort' /*display the before array elements.*/
|
||||
say copies('▒', 60) /*show a separator line between sorts. */
|
||||
call gnomeSort # /*invoke the well─known gnome sort. */
|
||||
call show ' after sort' /*display the after array elements.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
gen: @.=; @.1= '---the seven virtues---'; @.4= "Hope" ; @.7= 'Justice'
|
||||
@.2= '======================='; @.5= "Charity [Love]"; @.8= 'Prudence'
|
||||
@.3= 'Faith' ; @.6= "Fortitude" ; @.9= 'Temperance'
|
||||
do #=1 while @.#\==''; end; #= #-1; w= length(#); return /*get #items*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
gnomeSort: procedure expose @.; parse arg n; k= 2 /*N: is number items. */
|
||||
do j=3 while k<=n; p= k - 1 /*P: is previous item.*/
|
||||
if @.p<<=@.k then do; k= j; iterate; end /*order is OK so far. */
|
||||
_= @.p; @.p= @.k; @.k= _ /*swap two @ entries. */
|
||||
k= k - 1; if k==1 then k= j; else j= j-1 /*test for 1st index. */
|
||||
end /*j*/; return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: do j=1 for #; say ' element' right(j, w) arg(1)":" @.j; end; return
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* 28.06.2014 Walter Pachl cf ooRexx version 2
|
||||
* only style changes (reformatting) and adapt for ooRexx compatibility
|
||||
* NOTE that leading blanks are ignored in the comparison (' Justice')
|
||||
* unless strict comparison is used (i.e., 'If x.km<<=x.k Then')
|
||||
* 30.06.2014 WP added the missing else clause
|
||||
*--------------------------------------------------------------------*/
|
||||
/* generate the array elements. */
|
||||
Call gen '---the seven virtues---','=======================',,
|
||||
'Faith','Hope','Charity [Love]','Fortitude',' Justice',,
|
||||
'Prudence','Temperance'
|
||||
Call show 'before sort' /* show "before" array elements.*/
|
||||
Call gnomeSort /* invoke the infamous gnome sort.*/
|
||||
Call show ' after sort' /* show "after" array elements.*/
|
||||
Exit /* done. */
|
||||
|
||||
gnomesort: Procedure Expose x.
|
||||
k=2
|
||||
Do j=3 While k<=x.0
|
||||
km=k-1
|
||||
If x.km<=x.k Then
|
||||
k=j
|
||||
Else Do
|
||||
t=x.km; x.km=x.k; x.k=t /* swap two entries in the array. */
|
||||
k=k-1
|
||||
If k==1 Then
|
||||
k=j
|
||||
Else
|
||||
j=j-1
|
||||
End
|
||||
End
|
||||
Return
|
||||
|
||||
gen: Procedure Expose x.
|
||||
Do i=1 To arg()
|
||||
x.i=arg(i)
|
||||
End
|
||||
x.0=arg()
|
||||
Return
|
||||
|
||||
show: Procedure Expose x.
|
||||
Say arg(1)
|
||||
Do i=1 To x.0
|
||||
Say 'element' right(i,2) x.i
|
||||
End
|
||||
Return
|
||||
Loading…
Add table
Add a link
Reference in a new issue