MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / heapify

Function heapify

sorts/heap_sort.py:16–28  ·  view source on GitHub ↗
(unsorted, index, heap_size)

Source from the content-addressed store, hash-verified

14
15
16def heapify(unsorted, index, heap_size):
17 largest = index
18 left_index = 2 * index + 1
19 right_index = 2 * index + 2
20 if left_index < heap_size and unsorted[left_index] > unsorted[largest]:
21 largest = left_index
22
23 if right_index < heap_size and unsorted[right_index] > unsorted[largest]:
24 largest = right_index
25
26 if largest != index:
27 unsorted[largest], unsorted[index] = unsorted[index], unsorted[largest]
28 heapify(unsorted, largest, heap_size)
29
30
31def heap_sort(unsorted):

Callers 1

heap_sortFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected