Sorting algorithms/Heapsort: Difference between revisions

Content added Content deleted
Line 2,219: Line 2,219:
=={{header|EasyLang}}==
=={{header|EasyLang}}==


<syntaxhighlight lang="text">subr make_heap
<syntaxhighlight lang="text">
func sort . d[] .
for i = 1 to n - 1
n = len d[]
if data[i] > data[(i - 1) / 2]
# make heap
for i = 2 to n
if d[i] > d[(i + 1) div 2]
j = i
j = i
repeat
while data[j] > data[(j - 1) / 2]
swap data[j] data[(j - 1) / 2]
h = (j + 1) div 2
j = (j - 1) / 2
until d[j] <= d[h]
swap d[j] d[h]
j = h
.
.
.
.
.
.
for i = n downto 2
.
swap d[1] d[i]
subr sort
n = len data[]
j = 1
ind = 2
call make_heap
for i = n - 1 downto 1
swap data[0] data[i]
j = 0
ind = 1
while ind < i
while ind < i
if ind + 1 < i and data[ind + 1] > data[ind]
if ind + 1 < i and d[ind + 1] > d[ind]
ind += 1
ind += 1
.
.
if data[j] < data[ind]
if d[j] < d[ind]
swap data[j] data[ind]
swap d[j] d[ind]
.
.
j = ind
j = ind
ind = 2 * j + 1
ind = 2 * j
.
.
.
.
.
.
data[] = [ 29 4 72 44 55 26 27 77 92 5 ]
data[] = [ 29 4 72 44 55 26 27 77 92 5 ]
call sort
call sort data[]
print data[]</syntaxhighlight>
print data[]
</syntaxhighlight>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==