2 parents dfb83df + 345d371 commit f335dd8Copy full SHA for f335dd8
1 file changed
pygorithm/sorting/heap_sort.py
@@ -13,11 +13,15 @@
13
def sort(_list):
14
"""
15
heap sort algorithm
16
+ Create the heap using heapify().
17
+ This is an implementation of max-heap, so after bullding the heap, the max element is at the top (_list[0]).
18
+ We move it to the end of the list (_list[end]), which will later become the sorted list.
19
+ After moving this element to the end, we take the element in the end to the top and shift it down to its right location in the heap.
20
+ We proceed to do the same for all elements in the heap, such that in the end we're left with the sorted list.
21
22
:param _list: list of values to sort
23
:return: sorted values
24
- # TODO: Add description of how this works!
25
26
# create the heap
27
heapify(_list)
0 commit comments