|
@@ -15,7 +15,43 @@ def mergeSort(lista):
|
15
|
15
|
|
16
|
16
|
def heapSort(lista):
|
17
|
17
|
#definan el algoritmo de ordenamiento heapsort
|
18
|
|
- return lista
|
|
18
|
+ #Andrea V. Nieves
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+ #function def
|
|
22
|
+ def heapify(lista, n, i):
|
|
23
|
+ biggest = i
|
|
24
|
+ left = 2*i + 1
|
|
25
|
+ right = 2*i + 2
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+ if left < n and lista[left] > lista[i]:
|
|
29
|
+ biggest = left
|
|
30
|
+ else:
|
|
31
|
+ biggest = i
|
|
32
|
+
|
|
33
|
+ if right< n and lista[right] > lista[biggest]:
|
|
34
|
+ biggest = right
|
|
35
|
+
|
|
36
|
+ if biggest != i:
|
|
37
|
+ lista[i], lista[biggest] = lista[biggest], lista[i]
|
|
38
|
+ heapify(lista,n,biggest)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ #actual call
|
|
44
|
+ n = len(lista)
|
|
45
|
+
|
|
46
|
+ for i in range(n // 2 - 1, -1, -1):
|
|
47
|
+ heapify(lista, n, i)
|
|
48
|
+
|
|
49
|
+ for i in range(n - 1, 0, -1):
|
|
50
|
+ lista[i], lista[0] = lista[0], lista[i]
|
|
51
|
+ heapify(lista, i, 0)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ return lista
|
19
|
55
|
|
20
|
56
|
def quickSort(lista):
|
21
|
57
|
#definan el algoritmo de ordenamiento quicksort
|