Sorting algorithms/Heapsort: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) m (Added Delphi reference to Pascal code) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 63: | Line 63: | ||
Write a function to sort a collection of integers using heapsort. |
Write a function to sort a collection of integers using heapsort. |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F siftdown(&lst, start, end) |
|||
V root = start |
|||
L |
|||
V child = root * 2 + 1 |
|||
I child > end |
|||
L.break |
|||
I child + 1 <= end & lst[child] < lst[child + 1] |
|||
child++ |
|||
I lst[root] < lst[child] |
|||
swap(&lst[root], &lst[child]) |
|||
root = child |
|||
E |
|||
L.break |
|||
F heapsort(&lst) |
|||
L(start) ((lst.len - 2) I/ 2 .. 0).step(-1) |
|||
siftdown(&lst, start, lst.len - 1) |
|||
L(end) (lst.len - 1 .< 0).step(-1) |
|||
swap(&lst[end], &lst[0]) |
|||
siftdown(&lst, 0, end - 1) |
|||
V arr = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] |
|||
heapsort(&arr) |
|||
print(arr)</lang> |
|||
{{out}} |
|||
<pre> |
|||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|||
</pre> |
|||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
Line 206: | Line 240: | ||
-31 0 1 2 2 4 45 58 65 69 74 82 82 83 88 89 99 104 112 782 |
-31 0 1 2 2 4 45 58 65 69 74 82 82 83 88 89 99 104 112 782 |
||
</pre> |
</pre> |
||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |