Sorting algorithms/Heapsort: Difference between revisions
m
→{{header|Julia}}
Line 1,994:
=={{header|Julia}}==
<lang julia>
function pd!(a, first, last)
while (c = 2 * first - 1) < last
if c < last && a[c] < a[c + 1]
Line 2,000 ⟶ 2,002:
end
if a[first] < a[c]
swapa(a
first = c
else
Line 2,010 ⟶ 2,012:
hfy!(a, n) = (f = div(n, 2); while f >= 1 pd!(a, f, n); f -= 1 end)
heapsort!(a) = (n = length(a); hfy!(a, n); l = n; while l > 1 swapa(a
a = shuffle(collect(1:12))
|