update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -0,0 +1,72 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method radixSort(tlist = Rexx[]) public static returns Rexx[]
|
||||
|
||||
-- scale the array to start at zero to allow handling of -ve values
|
||||
parse getLimits(tlist) maxn minn maxl .
|
||||
tlist = rescale(tlist, minn)
|
||||
|
||||
loop px = maxl to 1 by -1
|
||||
bukits = ''
|
||||
loop ix = 0 to tlist.length - 1
|
||||
cval = tlist[ix].right(maxl, 0)
|
||||
parse cval . =(px) digit +1 .
|
||||
bukits[digit] = bukits[digit] (cval + 0) -- simulates a stack
|
||||
end ix
|
||||
intermediates = ''
|
||||
loop bi = 0 to 9
|
||||
intermediates = intermediates bukits[bi] -- sumulates unstack
|
||||
end bi
|
||||
-- reload array
|
||||
loop iw = 1 to intermediates.words()
|
||||
tlist[iw - 1] = intermediates.word(iw)
|
||||
end iw
|
||||
end px
|
||||
|
||||
-- restore the array to original scale
|
||||
tlist = rescale(tlist, -minn)
|
||||
return tlist
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method rescale(arry = Rexx[], newbase) private static returns Rexx[]
|
||||
loop ix = 0 to arry.length - 1
|
||||
arry[ix] = arry[ix] - newbase
|
||||
end ix
|
||||
return arry
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method getLimits(arry = Rexx[]) private static returns Rexx
|
||||
maxn = 0
|
||||
minn = 0
|
||||
maxl = 0
|
||||
loop i_ = 0 to arry.length - 1
|
||||
maxn = maxn.max(arry[i_])
|
||||
minn = minn.min(arry[i_])
|
||||
end i_
|
||||
maxl = (maxn - minn).length()
|
||||
return maxn minn maxl
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) private static
|
||||
lists = [-
|
||||
[2, 24, 45, 0, 66, 75, 170, -802, -90, 1066, 666], -
|
||||
[170, 45, 75, 90, 2, 24, 802, 66], -
|
||||
[10, 9, 8, 7, 8, 5, 4, 3, 2, 1, 0], -
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -
|
||||
[-10, -9, -8, -7, -8, -5, -4, -3, -2, -1, -0], -
|
||||
[-0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10], -
|
||||
[-10, -19, -18, -17, -18, -15, -14, -13, -12, -11, -100], -
|
||||
[10, 9, 8, 7, 8, 5, 4, 3, 2, 1, 0, -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10], -
|
||||
[-10, -9, -8, -7, -8, -5, -4, -3, -2, -1, -0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -
|
||||
]
|
||||
|
||||
loop il = 0 to lists.length - 1
|
||||
tlist = lists[il]
|
||||
say ' Input:' Arrays.asList(tlist)
|
||||
say 'Output:' Arrays.asList(radixSort(tlist))
|
||||
say
|
||||
end il
|
||||
return
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
import java.util.Queue
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method radixSort(tlist = Rexx[]) public static returns Rexx[]
|
||||
|
||||
-- scale the array to start at zero to allow handling of -ve values
|
||||
limits = ''
|
||||
parse '!MAXN !MINN !MAXL' maxn_ minn_ maxl_ .
|
||||
parse getLimits(tlist) maxn minn maxl .
|
||||
limits[maxn_] = maxn
|
||||
limits[minn_] = minn
|
||||
limits[maxl_] = maxl
|
||||
tlist = rescale(tlist, limits[minn_])
|
||||
|
||||
loop px = limits[maxl_] to 1 by -1
|
||||
bukits = Queue[10] -- stacks for digits 0 .. 9
|
||||
loop ix = 0 while ix < tlist.length
|
||||
cval = tlist[ix].right(limits[maxl_], 0)
|
||||
parse cval . =(px) digit +1 . -- extract next digit (fun with parse)
|
||||
-- alternatively: digit = (cval % (10 ** (px - 1))) // 10
|
||||
if bukits[digit] == null then bukits[digit] = LinkedList()
|
||||
bukits[digit].add((cval + 0))
|
||||
end ix
|
||||
|
||||
intermediates = ArrayList()
|
||||
loop bi = 0 to 9
|
||||
if bukits[bi] \= null then loop while bukits[bi].size() > 0
|
||||
nextd = bukits[bi].poll()
|
||||
intermediates.add(nextd)
|
||||
end
|
||||
end bi
|
||||
|
||||
-- reload result array
|
||||
loop iw = 0 while iw < intermediates.size()
|
||||
tlist[iw] = Rexx intermediates.get(iw)
|
||||
end iw
|
||||
end px
|
||||
|
||||
-- restore the array to original scale
|
||||
tlist = rescale(tlist, -limits[minn_])
|
||||
return tlist
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method rescale(arry = Rexx[], newbase) private static returns Rexx[]
|
||||
loop ix = 0 to arry.length - 1
|
||||
arry[ix] = arry[ix] - newbase
|
||||
end ix
|
||||
return arry
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method getLimits(arry = Rexx[]) private static returns Rexx
|
||||
maxn = 0
|
||||
minn = 0
|
||||
maxl = 0
|
||||
loop i_ = 0 to arry.length - 1
|
||||
maxn = maxn.max(arry[i_])
|
||||
minn = minn.min(arry[i_])
|
||||
end i_
|
||||
maxl = (maxn - minn).length()
|
||||
return maxn minn maxl
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) private static
|
||||
lists = [-
|
||||
[2, 24, 45, 0, 66, 75, 170, -802, -90, 1066, 666], -
|
||||
[170, 45, 75, 90, 2, 24, 802, 66], -
|
||||
[10, 9, 8, 7, 8, 5, 4, 3, 2, 1, 0], -
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -
|
||||
[-10, -9, -8, -7, -8, -5, -4, -3, -2, -1, -0], -
|
||||
[-0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10], -
|
||||
[-10, -19, -18, -17, -18, -15, -14, -13, -12, -11, -100], -
|
||||
[10, 9, 8, 7, 8, 5, 4, 3, 2, 1, 0, -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10], -
|
||||
[-10, -9, -8, -7, -8, -5, -4, -3, -2, -1, -0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -
|
||||
]
|
||||
|
||||
loop il = 0 to lists.length - 1
|
||||
tlist = lists[il]
|
||||
say ' Input:' Arrays.asList(tlist)
|
||||
say 'Output:' Arrays.asList(radixSort(tlist))
|
||||
say
|
||||
end il
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue