MCPcopy Create free account
hub / github.com/ActiveState/code / heapify

Function heapify

recipes/Python/577688_heap_sort/recipe-577688.py:1–13  ·  view source on GitHub ↗
(array, start, end, cmp)

Source from the content-addressed store, hash-verified

1def heapify(array, start, end, cmp): # array is almost a heap (except the root)
2 root = start
3 while root * 2 + 1 < end:
4 child = root * 2 + 1
5 if child + 1 < end:
6 v, k = cmp((array[root], root), (array[child], child), (array[child + 1], child + 1))
7 else:
8 v, k = cmp((array[root], root), (array[child], child))
9 if not k == root:
10 array[root], array[k] = array[k], array[root]
11 root = k
12 else:
13 break
14
15def build_heap_max(array):
16 length = len(array)

Callers 6

build_heap_maxFunction · 0.70
heap_sortFunction · 0.70
_rebuild_heapMethod · 0.50
__init__Method · 0.50
heapifying_smallestFunction · 0.50
primMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected