Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,2 @@
|
|||
shellSort 8 6 4 2 1 3 5 7 9
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
siz = 100
|
||||
dim a(siz)
|
||||
for i = 1 to siz
|
||||
a(i) = int(rnd(1) * 1000)
|
||||
next
|
||||
|
||||
' -------------------------------
|
||||
' Shell Sort
|
||||
' -------------------------------
|
||||
incr = int(siz / 2)
|
||||
WHILE incr > 0
|
||||
for i = 1 to siz
|
||||
j = i
|
||||
temp = a(i)
|
||||
WHILE (j >= incr+1 and a(abs(j-incr)) > temp)
|
||||
a(j) = a(j-incr)
|
||||
j = j - incr
|
||||
wend
|
||||
a(j) = temp
|
||||
next
|
||||
IF incr = 2 THEN
|
||||
incr = 1
|
||||
ELSE
|
||||
incr = int(incr * (5 / 11))
|
||||
end if
|
||||
WEND
|
||||
|
||||
for i = 1 to siz
|
||||
print a(i)
|
||||
next
|
||||
|
|
@ -1,54 +1,48 @@
|
|||
/*REXX program sorts an (stemmed) array using the shellsort method. */
|
||||
call gen@ /*generate the array elements. */
|
||||
call show@ 'before sort' /*show the before array elements.*/
|
||||
call shellSort # /*invoke the shell sort. */
|
||||
call show@ ' after sort' /*show the after array elements.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
|
||||
gen@: @.= /*assign default value to stem. */
|
||||
@.1='3 character abbreviations for states of the USA' /*predates ZIP.*/
|
||||
/*REXX program sorts a stemmed array using the shell sort algorithm. */
|
||||
call gen /*generate the array elements. */
|
||||
call show 'before sort' /*display the before array elements. */
|
||||
say copies('▒',75) /*displat a separator line (a fence). */
|
||||
call shellSort # /*invoke the shell sort. */
|
||||
call show ' after sort' /*display the after array elements. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────GEN subroutine────────────────────────────*/
|
||||
gen: @.= /*assign a default value to stem array.*/
|
||||
@.1='3 character abbreviations for states of the USA' /*predates ZIP code.*/
|
||||
@.2='==============================================='
|
||||
@.3='RHO Rhode Island and Providence Plantations' ; @.36='NMX New Mexico'
|
||||
@.4='CAL California' ; @.20='NEV Nevada' ; @.37='IND Indiana'
|
||||
@.5='KAN Kansas' ; @.21='TEX Texas' ; @.38='MOE Missouri'
|
||||
@.6='MAS Massachusetts' ; @.22='VGI Virginia' ; @.39='COL Colorado'
|
||||
@.7='WAS Washington' ; @.23='OHI Ohio' ; @.40='CON Connecticut'
|
||||
@.8='HAW Hawaii' ; @.24='NHM New Hampshire'; @.41='MON Montana'
|
||||
@.9='NCR North Carolina'; @.25='MAE Maine' ; @.42='LOU Louisiana'
|
||||
@.10='SCR South Carolina'; @.26='MIC Michigan' ; @.43='IOW Iowa'
|
||||
@.11='IDA Idaho' ; @.27='MIN Minnesota' ; @.44='ORE Oregon'
|
||||
@.12='NDK North Dakota' ; @.28='MIS Mississippi' ; @.45='ARK Arkansas'
|
||||
@.13='SDK South Dakota' ; @.29='WIS Wisconsin' ; @.46='ARZ Arizona'
|
||||
@.14='NEB Nebraska' ; @.30='OKA Oklahoma' ; @.47='UTH Utah'
|
||||
@.15='DEL Delaware' ; @.31='ALA Alabama' ; @.48='KTY Kentucky'
|
||||
@.16='PEN Pennsylvania' ; @.32='FLA Florida' ; @.49='WVG West Virginia'
|
||||
@.17='TEN Tennessee' ; @.33='MLD Maryland' ; @.50='NWJ New Jersey'
|
||||
@.18='GEO Georgia' ; @.34='ALK Alaska' ; @.51='NYK New York'
|
||||
@.19='VER Vermont' ; @.35='ILL Illinois' ; @.52='WYO Wyoming'
|
||||
|
||||
do #=1 while @.#\=='' /*find how many entries in array.*/
|
||||
end /*#*/
|
||||
#=#-1 /*adjust # of entries slightly.*/
|
||||
@.3='RHO Rhode Island and Providence Plantations' ; @.36='NMX New Mexico'
|
||||
@.4='CAL California' ; @.20='NEV Nevada' ; @.37='IND Indiana'
|
||||
@.5='KAN Kansas' ; @.21='TEX Texas' ; @.38='MOE Missouri'
|
||||
@.6='MAS Massachusetts' ; @.22='VGI Virginia' ; @.39='COL Colorado'
|
||||
@.7='WAS Washington' ; @.23='OHI Ohio' ; @.40='CON Connecticut'
|
||||
@.8='HAW Hawaii' ; @.24='NHM New Hampshire'; @.41='MON Montana'
|
||||
@.9='NCR North Carolina'; @.25='MAE Maine' ; @.42='LOU Louisiana'
|
||||
@.10='SCR South Carolina'; @.26='MIC Michigan' ; @.43='IOW Iowa'
|
||||
@.11='IDA Idaho' ; @.27='MIN Minnesota' ; @.44='ORE Oregon'
|
||||
@.12='NDK North Dakota' ; @.28='MIS Mississippi' ; @.45='ARK Arkansas'
|
||||
@.13='SDK South Dakota' ; @.29='WIS Wisconsin' ; @.46='ARZ Arizona'
|
||||
@.14='NEB Nebraska' ; @.30='OKA Oklahoma' ; @.47='UTH Utah'
|
||||
@.15='DEL Delaware' ; @.31='ALA Alabama' ; @.48='KTY Kentucky'
|
||||
@.16='PEN Pennsylvania' ; @.32='FLA Florida' ; @.49='WVG West Virginia'
|
||||
@.17='TEN Tennessee' ; @.33='MLD Maryland' ; @.50='NWJ New Jersey'
|
||||
@.18='GEO Georgia' ; @.34='ALK Alaska' ; @.51='NYK New York'
|
||||
@.19='VER Vermont' ; @.35='ILL Illinois' ; @.52='WYO Wyoming'
|
||||
do #=1 while @.#\==''; end; #=#-1 /*determine number of entries in array.*/
|
||||
return
|
||||
/*──────────────────────────────────SHELLSORT subroutine────────────────*/
|
||||
/*──────────────────────────────────SHELLSORT subroutine──────────────────────*/
|
||||
shellSort: procedure expose @.; parse arg N
|
||||
i=N%2 /*integer divide N by two. */
|
||||
do while i\==0
|
||||
do j=i+1 to N; k=j; kmi=k-i
|
||||
_=@.j
|
||||
do while k>=i+1 & @.kmi>_; @.k=@.kmi
|
||||
k=k-i; kmi=k-i
|
||||
end /*while k>=i+1 & ···*/
|
||||
@.k=_
|
||||
end /*j*/
|
||||
i=N%2 /*% is integer division in REXX. */
|
||||
do while i\==0
|
||||
do j=i+1 to N; k=j; p=k-i /*P: previous item*/
|
||||
_=@.j
|
||||
do while k>=i+1 & @.p>_; @.k=@.p
|
||||
k=k-i; p=k-i
|
||||
end /*while k≥i+1*/
|
||||
@.k=_
|
||||
end /*j*/
|
||||
|
||||
if i==2 then i=1
|
||||
else i=i*5%11
|
||||
end /*while i\==0*/
|
||||
return
|
||||
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
|
||||
show@: do j=1 for #
|
||||
say 'element' right(j,length(#)) arg(1)': ' @.j
|
||||
end /*j*/
|
||||
say copies('─',79) /*show a separator line (a fence)*/
|
||||
if i==2 then i=1
|
||||
else i=i*5%11
|
||||
end /*while i¬==0*/
|
||||
return
|
||||
/*──────────────────────────────────SHOW subroutine───────-───────────────────*/
|
||||
show: do j=1 for #; say 'element' right(j,length(#)) arg(1)': ' @.j; end; return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue