Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,81 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
import java.util.List
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method pancakeSort(tlist = List, debug = (1 == 0)) private static returns List
|
||||
|
||||
if tlist.size() > 1 then do
|
||||
loop i_ = tlist.size() by -1 while i_ > 1
|
||||
maxPos = 0
|
||||
loop a_ = 0 while a_ < i_
|
||||
if Rexx tlist.get(a_) > Rexx tlist.get(maxPos) then maxPos = a_
|
||||
end a_
|
||||
if maxPos = i_ - 1 then iterate i_
|
||||
if maxPos > 0 then pancakeFlip(tlist, maxPos + 1, debug)
|
||||
pancakeFlip(tlist, i_, debug)
|
||||
end i_
|
||||
end
|
||||
return tlist
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method pancakeFlip(tlist = List, offset, debug = (1 == 0)) private static returns List
|
||||
z_ = offset - 1
|
||||
pl = 3
|
||||
if debug then do
|
||||
plx = offset.length()
|
||||
if plx > pl then pl = plx
|
||||
say ' flip{1-'offset.right(pl, 0)'} Before:' tlist
|
||||
end
|
||||
loop i_ = 0 while i_ < z_
|
||||
Collections.swap(tlist, i_, z_)
|
||||
z_ = z_ - 1
|
||||
end i_
|
||||
if debug then do
|
||||
say ' flip{1-'offset.right(pl, 0)'} After:' tlist
|
||||
end
|
||||
return tlist
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) private static
|
||||
|
||||
isTrue = (1 == 1)
|
||||
isFalse = \isTrue
|
||||
|
||||
parse arg debug .
|
||||
if '-debug'.abbrev(debug.lower(), 2) then debug = isTrue
|
||||
else debug = isFalse
|
||||
|
||||
lists = sampleData()
|
||||
loop il = 1 to lists[0]
|
||||
clist = words2list(lists[il])
|
||||
say ' Input:' clist
|
||||
say 'Output:' pancakeSort(clist, debug)
|
||||
say
|
||||
end il
|
||||
|
||||
return
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method sampleData() private static
|
||||
lists = ''
|
||||
i_ = 0
|
||||
i_ = i_ + 1; lists[0] = i_; lists[i_] = '1 4 3 5 2 9 8 7 6'
|
||||
i_ = i_ + 1; lists[0] = i_; lists[i_] = '10 -9 8 -7 6 -5 4 -3 2 -1 0 -10 9 -8 7 -6 5 -4 3 -2 1'
|
||||
i_ = i_ + 1; lists[0] = i_; lists[i_] = '88 18 31 44 4 0 8 81 14 78 20 76 84 33 73 75 82 5 62 70 12 7 1'
|
||||
i_ = i_ + 1; lists[0] = i_; lists[i_] = '10 10.0 10.00 1 -10.0 10. -1'
|
||||
i_ = i_ + 1; lists[0] = i_; lists[i_] = 'To be or not to be that is the question'
|
||||
i_ = i_ + 1; lists[0] = i_; lists[i_] = '1'
|
||||
return lists
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method words2list(wordlist) private static returns List
|
||||
|
||||
clist = ArrayList()
|
||||
loop w_ = 1 to wordlist.words()
|
||||
clist.add(wordlist.word(w_))
|
||||
end w_
|
||||
|
||||
return clist
|
||||
Loading…
Add table
Add a link
Reference in a new issue