(array, start, end, cmp)
| 1 | def 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 | |
| 15 | def build_heap_max(array): |
| 16 | length = len(array) |
no outgoing calls
no test coverage detected