Anonymous user
Sorting algorithms/Heapsort: Difference between revisions
→{{header|Groovy}}: changed the loops to even more readable for loops.
imported>SerErris (→{{header|Groovy}}: added a better to read and commented version of the code.) |
imported>SerErris (→{{header|Groovy}}: changed the loops to even more readable for loops.) |
||
Line 2,958:
// ensure that each parent is lager than the child for all parent/childs.
// (list.size() -2) / 2 = last parent in the heap.
for (start in ((list.size()
siftDown(list, start, list.size() - 1)
}
Line 2,968:
//Run the list backwards and
//for end = (size of list -1 ) to 0
for (end in (list.size()-1)..0 )
makeSwap(list, 0, end) //put the top of the heap to the end (largest element)
siftDown(list, 0, end-1) //ensure that the rest is a heap again
|