Explorar el Código

Updated heap.py

luislopez66 hace 2 años
padre
commit
eef072e15e
Se han modificado 1 ficheros con 2 adiciones y 1 borrados
  1. 2
    1
      heap.py

+ 2
- 1
heap.py Ver fichero

@@ -31,7 +31,8 @@ def heapify(lista, n, i):
31 31
 
32 32
 		# If necessary, this changes root by swapping va-
33 33
 		# lues
34
-		lista[i], lista[largest] = lista[largest], lista[i]
34
+        if largest != i:
35
+            lista[i], lista[largest] = lista[largest], lista[i]
35 36
 
36 37
 		# This heapifies the root repeatedly
37 38
 		heapify(lista, n, largest)