|
@@ -58,7 +58,43 @@ def mergeSort(lista):
|
58
|
58
|
|
59
|
59
|
def heapSort(lista):
|
60
|
60
|
#definan el algoritmo de ordenamiento heapsort
|
61
|
|
- return lista
|
|
61
|
+ #Andrea V. Nieves
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+ #function def
|
|
65
|
+ def heapify(lista, n, i):
|
|
66
|
+ biggest = i
|
|
67
|
+ left = 2*i + 1
|
|
68
|
+ right = 2*i + 2
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+ if left < n and lista[left] > lista[i]:
|
|
72
|
+ biggest = left
|
|
73
|
+ else:
|
|
74
|
+ biggest = i
|
|
75
|
+
|
|
76
|
+ if right< n and lista[right] > lista[biggest]:
|
|
77
|
+ biggest = right
|
|
78
|
+
|
|
79
|
+ if biggest != i:
|
|
80
|
+ lista[i], lista[biggest] = lista[biggest], lista[i]
|
|
81
|
+ heapify(lista,n,biggest)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+ #actual call
|
|
87
|
+ n = len(lista)
|
|
88
|
+
|
|
89
|
+ for i in range(n // 2 - 1, -1, -1):
|
|
90
|
+ heapify(lista, n, i)
|
|
91
|
+
|
|
92
|
+ for i in range(n - 1, 0, -1):
|
|
93
|
+ lista[i], lista[0] = lista[0], lista[i]
|
|
94
|
+ heapify(lista, i, 0)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+ return lista
|
62
|
98
|
|
63
|
99
|
def quickSort(lista):
|
64
|
100
|
#definan el algoritmo de ordenamiento quicksort
|