(heap, start, size, positions)
| 11 | nodePosition[vertex] = pos |
| 12 | |
| 13 | def topToBottom(heap, start, size, positions): |
| 14 | if start > size // 2 - 1: |
| 15 | return |
| 16 | else: |
| 17 | if 2 * start + 2 >= size: |
| 18 | m = 2 * start + 1 |
| 19 | else: |
| 20 | if heap[2 * start + 1] < heap[2 * start + 2]: |
| 21 | m = 2 * start + 1 |
| 22 | else: |
| 23 | m = 2 * start + 2 |
| 24 | if heap[m] < heap[start]: |
| 25 | temp, temp1 = heap[m], positions[m] |
| 26 | heap[m], positions[m] = heap[start], positions[start] |
| 27 | heap[start], positions[start] = temp, temp1 |
| 28 | |
| 29 | temp = getPosition(positions[m]) |
| 30 | setPosition(positions[m], getPosition(positions[start])) |
| 31 | setPosition(positions[start], temp) |
| 32 | |
| 33 | topToBottom(heap, m, size, positions) |
| 34 | |
| 35 | # Update function if value of any node in min-heap decreases |
| 36 | def bottomToTop(val, index, heap, position): |
no test coverage detected