Sorting algorithms/Heapsort: Difference between revisions

Content added Content deleted
(→‎{{header|Groovy}}: new solution)
Line 795: Line 795:
=={{header|Groovy}}==
=={{header|Groovy}}==
Loose translation of the pseudocode:
Loose translation of the pseudocode:
<lang groovy>def makeSwap = { a, i, j -> print "."; def t = a[j]; a[j] = a[i]; a[i] = t }
<lang groovy>def makeSwap = { a, i, j = i+1 -> print "."; a[[j,i]] = a[[i,j]] }


def checkSwap = { a, i, j -> [(a[i] > a[j])].find { it }.each { makeSwap(a, i, j) } }
def checkSwap = { list, i, j = i+1 -> [(list[i] > list[j])].find{ it }.each { makeSwap(list, i, j) } }


def siftDown = { a, start, end ->
def siftDown = { a, start, end ->