瀏覽代碼

Updated heap.py

luislopez66 2 年之前
父節點
當前提交
eef072e15e
共有 1 個檔案被更改,包括 2 行新增1 行删除
  1. 2
    1
      heap.py

+ 2
- 1
heap.py 查看文件

@@ -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)