Browse Source

update sorting.py

luislopez66 2 years ago
parent
commit
4bd6d6f25d
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      sorting.py

+ 5
- 2
sorting.py View File

@@ -70,10 +70,13 @@ def heapify(lista, n, i):
70 70
 def heapSort(lista):
71 71
 
72 72
 		n = len(lista)
73
-		for i in range((n // 2) - 1, -1, -1):
73
+		n2 = (n // 2) - 1
74
+		nMinus = n - 1
75
+
76
+		for i in range(n2, -1, -1):
74 77
 			heapify(lista, n, i)
75 78
 
76
-		for i in range(n-1, -1, -1):
79
+		for i in range(nMinus, -1, -1):
77 80
 			lista[i], lista[0] = lista[0], lista[i]
78 81
 			heapify(lista, i, 0)
79 82