|
@@ -21,9 +21,9 @@ def heapSort(lista):
|
21
|
21
|
"""
|
22
|
22
|
def max_heapify(lista, idx: int, heap_size: int):
|
23
|
23
|
"""Convertir el nodo `idx` y sus descendientes en un max heap."""
|
24
|
|
- left_idx: int = 2 * idx + 1
|
25
|
|
- right_idx: int = 2 * idx + 2
|
26
|
|
- largestval_idx: int = idx
|
|
24
|
+ left_idx = 2 * idx + 1
|
|
25
|
+ right_idx = 2 * idx + 2
|
|
26
|
+ largestval_idx = idx
|
27
|
27
|
if left_idx < heap_size and lista[idx] < lista[left_idx]:
|
28
|
28
|
largestval_idx = left_idx
|
29
|
29
|
if right_idx < heap_size and lista[largestval_idx] < lista[right_idx]:
|
|
@@ -32,7 +32,7 @@ def heapSort(lista):
|
32
|
32
|
lista[idx], lista[largestval_idx] = lista[largestval_idx], lista[idx]
|
33
|
33
|
max_heapify(lista, largestval_idx, heap_size)
|
34
|
34
|
|
35
|
|
- def build_max_heap(lista, heap_size: int):
|
|
35
|
+ def build_max_heap(lista, heap_size):
|
36
|
36
|
"""Construir un max heap the un heap dado."""
|
37
|
37
|
for idx in range((heap_size - 1) // 2, -1, -1):
|
38
|
38
|
max_heapify(lista, idx, heap_size)
|