Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,31 @@
|
|||
/*REXX program sorts a stemmed array using the gnome-sort algorithm.*/
|
||||
call gen@ /*generate the @. array elements.*/
|
||||
call show@ 'before sort' /*show "before" array elements.*/
|
||||
call gnomeSort # /*invoke the infamous gnome sort.*/
|
||||
call show@ ' after sort' /*show "after" array elements.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────GNOMESORT subroutine────────────────*/
|
||||
gnomeSort: procedure expose @.; parse arg n; k=2 /*n=num items.*/
|
||||
do j=3 while k<=n; km=k-1 /*KM=prev item*/
|
||||
if @.km<<=@.k then do; k=j; iterate; end /*OK so far···*/
|
||||
_=@.km; @.km=@.k; @.k=_ /*swap 2 entries in the @. array.*/
|
||||
k=k-1; if k==1 then k=j; else j=j-1 /*test index 1*/
|
||||
end /*j*/ /* [↑] perform gnome sort on @.*/
|
||||
return
|
||||
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
|
||||
gen@: !=... 'deadbeef'x ...; @.=! /*default none-value; allows null*/
|
||||
@.1 = '---the seven virtues---' /* [↓] indent the seven virtues.*/
|
||||
@.2 = '=======================' ; @.6 = 'Fortitude'
|
||||
@.3 = 'Faith' ; @.7 = 'Justice'
|
||||
@.4 = 'Hope' ; @.8 = 'Prudence'
|
||||
@.5 = 'Charity [Love]' ; @.9 = 'Temperance'
|
||||
|
||||
do #=1 while @.#\==!; end /*find the # of items in @ array.*/
|
||||
#=#-1 /*adjust the numer of items by 1.*/
|
||||
return
|
||||
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
|
||||
show@: do j=1 for # /* [↓] display all items for @. */
|
||||
say ' element' right(j,length(#)) arg(1)":" @.j
|
||||
end /*j*/ /* [↑] right justify the J num.*/
|
||||
say copies('■',60) /*show a separator line that fits*/
|
||||
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
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*REXX program sorts an array using the gnome-sort method. */
|
||||
call gen@ /*generate the array elements. */
|
||||
call show@ 'before sort' /*show "before" array elements.*/
|
||||
call gnomeSort highItem /*invoke the infamous gnome sort.*/
|
||||
call show@ ' after sort' /*show "after" array elements.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*─────────────────────────────────────gnomeSORT subroutine─────────────*/
|
||||
gnomeSort: procedure expose @.; parse arg n; k=2
|
||||
|
||||
do j=3 while k<=n; km=k-1
|
||||
if @.km<=@.k then k=j
|
||||
else do
|
||||
_=@.km /*swap two entries in the array. */
|
||||
@.km=@.k
|
||||
@.k=_
|
||||
k=k-1; if k==1 then k=j
|
||||
end
|
||||
end /*j*/
|
||||
return
|
||||
/*─────────────────────────────────────GEN@ subroutine──────────────────*/
|
||||
gen@: @.= /*assign a default value (null). */
|
||||
@.1='---the seven virtues---'
|
||||
@.2='======================='
|
||||
@.3='Faith'
|
||||
@.4='Hope'
|
||||
@.5='Charity [Love]'
|
||||
@.6='Fortitude'
|
||||
@.7='Justice'
|
||||
@.8='Prudence'
|
||||
@.9='Temperance'
|
||||
do highItem=1 while @.highItem\=='' /*find how many entries in array.*/
|
||||
end /*not much of a DO loop, eh? */
|
||||
highItem=highItem-1 /*because of DO, adjust highItem.*/
|
||||
return
|
||||
/*─────────────────────────────────────SHOW@ subroutine─────────────────*/
|
||||
show@: widthH=length(highItem) /*the maximum width of any line. */
|
||||
do j=1 for highItem /*show and tell time for array. */
|
||||
say 'element' right(j,widthH) arg(1)":" @.j /*make it pretty.*/
|
||||
end /*j*/
|
||||
say copies('─',60) /*show a separator line that fits*/
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue