Sorting algorithms/Heapsort: Difference between revisions
m
→{{header|Sidef}}: minor code simplifications
(Added EchoLisp) |
m (→{{header|Sidef}}: minor code simplifications) |
||
Line 3,087:
=={{header|Sidef}}==
<lang ruby>func
var root = start;
while ((2*root + 1) <= end) {
Line 3,093:
if ((child+1 <= end) && (a[child] < a[child + 1])) {
child += 1;
}
if (a[root] < a[child]) {
a[child, root] = a[root, child];
Line 3,102:
}
}
func heapify(a, count) {
var start = ((count - 2) / 2);
while (start >= 0) {
start -= 1;
}
}
func
heapify(a, count);
var end = (count - 1);
Line 3,117:
a[0, end] = a[end, 0];
end -= 1;
}
return a
}
var arr = (1..10 -> shuffle); # creates a shuffled array
say arr
say arr
{{out}}
<pre>[10, 5, 2, 1, 7, 6, 4, 8, 3, 9]
|