浏览代码

Updated heap.py

luislopez66 2 年前
父节点
当前提交
eef072e15e
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2
    1
      heap.py

+ 2
- 1
heap.py 查看文件

31
 
31
 
32
 		# If necessary, this changes root by swapping va-
32
 		# If necessary, this changes root by swapping va-
33
 		# lues
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
 		# This heapifies the root repeatedly
37
 		# This heapifies the root repeatedly
37
 		heapify(lista, n, largest)
38
 		heapify(lista, n, largest)