Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 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