Sorting algorithms/Heapsort: Difference between revisions
Content added Content deleted
Line 2,219: | Line 2,219: | ||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
<syntaxhighlight lang="text"> |
<syntaxhighlight lang="text"> |
||
func sort . d[] . |
|||
⚫ | |||
n = len d[] |
|||
⚫ | |||
# make heap |
|||
⚫ | |||
⚫ | |||
j = i |
j = i |
||
⚫ | |||
while data[j] > data[(j - 1) / 2] |
|||
h = (j + 1) div 2 |
|||
j = |
until d[j] <= d[h] |
||
⚫ | |||
⚫ | |||
. |
. |
||
. |
. |
||
. |
. |
||
⚫ | |||
. |
|||
swap d[1] d[i] |
|||
subr sort |
|||
j = 1 |
|||
ind = 2 |
|||
call make_heap |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
while ind < i |
while ind < i |
||
if ind + 1 < i and |
if ind + 1 < i and d[ind + 1] > d[ind] |
||
ind += 1 |
ind += 1 |
||
. |
. |
||
if |
if d[j] < d[ind] |
||
swap |
swap d[j] d[ind] |
||
. |
. |
||
j = ind |
j = ind |
||
ind = 2 * j |
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[] |
print data[] |
||
</syntaxhighlight> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |