|
@@ -10,7 +10,7 @@ Al final se imprimen los promedios de cada algortimo
|
10
|
10
|
from random import randint
|
11
|
11
|
import time
|
12
|
12
|
from merge import merge
|
13
|
|
-from heapq import heapify
|
|
13
|
+import heapq
|
14
|
14
|
|
15
|
15
|
# Python program for implementation of MergeSort
|
16
|
16
|
|
|
@@ -30,18 +30,17 @@ def mergeSort(lista, l, r):
|
30
|
30
|
mergeSort(lista, m+1, r)
|
31
|
31
|
merge(lista, l, m, r)
|
32
|
32
|
|
33
|
|
-def heapSort(lista):
|
|
33
|
+# Luis A. López Mañán
|
|
34
|
+# Code retreived from docs.python.org/3/library/heapq.html
|
|
35
|
+# October 11th, 2022
|
34
|
36
|
|
35
|
|
- n = len(lista)
|
36
|
|
- h1 = (n // 2) - 1
|
37
|
|
- for i in range(h1, -1, -1):
|
38
|
|
- heapify(lista[i])
|
|
37
|
+def heapSort(lista):
|
39
|
38
|
|
40
|
|
- for i in range(n-1, -1, -1):
|
41
|
|
- lista[i], lista[0] = lista[0], lista[i]
|
42
|
|
- heapify(lista[i])
|
|
39
|
+ h = []
|
43
|
40
|
|
44
|
|
- return lista
|
|
41
|
+ for val in lista:
|
|
42
|
+ heappush(h, val)
|
|
43
|
+ return [heappop(h) for i in range(len(h))]
|
45
|
44
|
|
46
|
45
|
def quickSort(lista):
|
47
|
46
|
#definan el algoritmo de ordenamiento quicksort
|