all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue