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,17 @@
/** Cocktail sort (in-place) */
def cocktailSort(array) {
def swapIndexes := 0..(array.size() - 2)
def directions := [swapIndexes, swapIndexes.descending()]
while (true) {
for direction in directions {
var swapped := false
for a ? (array[a] > array[def b := a + 1]) in direction {
def t := array[a]
array[a] := array[b]
array[b] := t
swapped := true
}
if (!swapped) { return }
}
}
}