all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,100 @@
/* NetRexx */
options replace format comments java crossref savelog symbols binary
import java.util.List
placesList = [String -
"UK London", "US New York", "US Boston", "US Washington" -
, "UK Washington", "US Birmingham", "UK Birmingham", "UK Boston" -
]
lists = [ -
placesList -
, quickSortSimple(String[] Arrays.copyOf(placesList, placesList.length)) -
, quickSortInplace(String[] Arrays.copyOf(placesList, placesList.length)) -
]
loop ln = 0 to lists.length - 1
cl = lists[ln]
loop ct = 0 to cl.length - 1
say cl[ct]
end ct
say
end ln
return
method quickSortSimple(array = String[]) public constant binary returns String[]
rl = String[array.length]
al = List quickSortSimple(Arrays.asList(array))
al.toArray(rl)
return rl
method quickSortSimple(array = List) public constant binary returns ArrayList
if array.size > 1 then do
less = ArrayList()
equal = ArrayList()
greater = ArrayList()
pivot = array.get(Random().nextInt(array.size - 1))
loop x_ = 0 to array.size - 1
if (Comparable array.get(x_)).compareTo(Comparable pivot) < 0 then less.add(array.get(x_))
if (Comparable array.get(x_)).compareTo(Comparable pivot) = 0 then equal.add(array.get(x_))
if (Comparable array.get(x_)).compareTo(Comparable pivot) > 0 then greater.add(array.get(x_))
end x_
less = quickSortSimple(less)
greater = quickSortSimple(greater)
out = ArrayList(array.size)
out.addAll(less)
out.addAll(equal)
out.addAll(greater)
array = out
end
return ArrayList array
method quickSortInplace(array = String[]) public constant binary returns String[]
rl = String[array.length]
al = List quickSortInplace(Arrays.asList(array))
al.toArray(rl)
return rl
method quickSortInplace(array = List, ixL = int 0, ixR = int array.size - 1) public constant binary returns ArrayList
if ixL < ixR then do
ixP = int ixL + (ixR - ixL) % 2
ixP = quickSortInplacePartition(array, ixL, ixR, ixP)
quickSortInplace(array, ixL, ixP - 1)
quickSortInplace(array, ixP + 1, ixR)
end
array = ArrayList(array)
return ArrayList array
method quickSortInplacePartition(array = List, ixL = int, ixR = int, ixP = int) public constant binary returns int
pivotValue = array.get(ixP)
rValue = array.get(ixR)
array.set(ixP, rValue)
array.set(ixR, pivotValue)
ixStore = ixL
loop i_ = ixL to ixR - 1
iValue = array.get(i_)
if (Comparable iValue).compareTo(Comparable pivotValue) < 0 then do
storeValue = array.get(ixStore)
array.set(i_, storeValue)
array.set(ixStore, iValue)
ixStore = ixStore + 1
end
end i_
storeValue = array.get(ixStore)
rValue = array.get(ixR)
array.set(ixStore, rValue)
array.set(ixR, storeValue)
return ixStore