Jump to content

Sorting algorithms/Comb sort: Difference between revisions

→‎{{header|Groovy}}: swap dots added
(→‎{{header|Groovy}}: new solution)
(→‎{{header|Groovy}}: swap dots added)
Line 481:
=={{header|Groovy}}==
Combsort solution:
<lang groovy>def checkSwapmakeSwap = { lista, i, j -> print "."; a[i] ^= a[j]; a[j] ^= a[i]; a[i] ^= a[j]
def doSwap = (list[i] > list[j])
if (doSwap) { list[i] ^= list[j]; list[j] ^= list[i]; list[i] ^= list[j]}
doSwap
}
 
def checkSwap = { a, i, j -> [(a[i] > a[j])].find { it }.each { makeSwap(a, i, j) } }
def combSort = { input ->
 
def combSort = { input ->
def swap = checkSwap.curry(input)
def size = input.size()
Line 503 ⟶ 501:
Combsort11 solution:
<lang groovy>def combSort11 = { input ->
def swap = checkSwap.curry(input)
 
def size = input.size()
def gap = size
def swapped = true
def swap = checkSwap.curry(input)
while (gap != 1 || swapped) {
gap = (gap / 1.247330950103979) as int
Line 524 ⟶ 521:
 
Output:
<pre>..................................................................................................................[4, 12, 14, 23, 24, 24, 31, 35, 38, 46, 51, 57, 57, 58, 76, 78, 89, 92, 95, 97, 99]
..........................................................................................................................[4, 12, 14, 23, 24, 24, 31, 35, 38, 46, 51, 57, 57, 58, 76, 78, 89, 92, 95, 97, 99]
 
...............................................................................................[0, 1, 4, 5, 7, 8, 12, 14, 18, 20, 31, 33, 44, 62, 70, 73, 75, 76, 78, 81, 82, 84, 88]
...............................................................................................[0, 1, 4, 5, 7, 8, 12, 14, 18, 20, 31, 33, 44, 62, 70, 73, 75, 76, 78, 81, 82, 84, 88]</pre>
</pre>
 
=={{header|Haskell}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.