Sorting algorithms/Heapsort: Difference between revisions
Content added Content deleted
(Added Elixir) |
m (added whitespace before the TOC, added other whitespace in the task's preamble.) |
||
Line 1: | Line 1: | ||
{{task|Sorting Algorithms}} {{Sorting Algorithm}} {{wikipedia|Heapsort}} |
{{task|Sorting Algorithms}} {{Sorting Algorithm}} {{wikipedia|Heapsort}} |
||
{{omit from|GUISS}} |
{{omit from|GUISS}} |
||
⚫ | |||
<br> |
|||
⚫ | |||
The basic idea is to turn the array into a binary heap structure, which has the property that it allows efficient retrieval and removal of the maximal element. |
The basic idea is to turn the array into a binary heap structure, which has the property that it allows efficient retrieval and removal of the maximal element. |
||
We repeatedly "remove" the maximal element from the heap, thus building the sorted list from back to front. |
We repeatedly "remove" the maximal element from the heap, thus building the sorted list from back to front. |
||
Heapsort requires random access, so can only be used on an array-like data structure. |
Heapsort requires random access, so can only be used on an array-like data structure. |
||
Line 51: | Line 56: | ||
'''else''' |
'''else''' |
||
'''return''' |
'''return''' |
||
<br> |
|||
Write a function to sort a collection of integers using heapsort. |
Write a function to sort a collection of integers using heapsort. |
||
<br><br> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |