|
@@ -2,11 +2,13 @@
|
2
|
2
|
|
3
|
3
|
"""
|
4
|
4
|
Programadores:
|
5
|
|
-
|
|
5
|
+Carlos J Corrada Bravo
|
|
6
|
+Diego Rodríguez
|
|
7
|
+Joel González
|
|
8
|
+Javier Santiago
|
|
9
|
+Luis Jusino
|
6
|
10
|
"""
|
7
|
|
-
|
8
|
11
|
"""
|
9
|
|
-Carlos J Corrada Bravo
|
10
|
12
|
Este programa calcula el promedio de tiempo de ejecución de cuatro algoritmos de ordenamiento
|
11
|
13
|
La variable maxValor define el valor maximo de los elementos de la lista
|
12
|
14
|
La variable largoLista define el largo de las listas a ordenar
|
|
@@ -54,12 +56,47 @@ def heapSort(listaHeap):
|
54
|
56
|
heapify(listaHeap, i, 0)
|
55
|
57
|
return listaHeap
|
56
|
58
|
|
|
59
|
+ return lista
|
|
60
|
+#Se le da credito al programador de la funcion al final del codigo
|
|
61
|
+
|
57
|
62
|
def quickSort(lista):
|
58
|
|
- #definan el algoritmo de ordenamiento quicksort
|
|
63
|
+ #definan el algoritmo de ordenamiento quicksort
|
59
|
64
|
return lista
|
60
|
65
|
|
61
|
66
|
def shellSort(lista):
|
62
|
|
- #definan el algoritmo de ordenamiento shellsort
|
|
67
|
+ # Subarrays are sorted according to intervals
|
|
68
|
+ # After each set of subarrays is sorted, interval value is updated and process repeats
|
|
69
|
+ # Function stops once iteration with interval = 1 has executed
|
|
70
|
+ # print(lista)
|
|
71
|
+ interval = len(lista) // 2
|
|
72
|
+ while interval > 0:
|
|
73
|
+ # Process repeats for each value between 1 -> interval
|
|
74
|
+ for i in range(0, interval):
|
|
75
|
+ # Starting index determines initial portion of the array that is sorted
|
|
76
|
+ sortedIndex = i
|
|
77
|
+ # Process repeats as long as the current value being considered is greater than the value to its left
|
|
78
|
+ # Being greater than the value to its left means that it is not in the correct location
|
|
79
|
+ j = i
|
|
80
|
+ while j + interval < len(lista):
|
|
81
|
+ if lista[j] > lista[j + interval]:
|
|
82
|
+ # Swapping values so that smaller value is to the left
|
|
83
|
+ temp = lista[j]
|
|
84
|
+ lista[j] = lista[j + interval]
|
|
85
|
+ lista[j + interval] = temp
|
|
86
|
+ # print(lista)
|
|
87
|
+ n = j
|
|
88
|
+ # Continue comparing value that was swapped left to other values to the left to make sure it is placed in the correct location
|
|
89
|
+ while n - interval >= 0 and lista[n] < lista[n - interval]:
|
|
90
|
+ # Swapping values so that smaller value is to the left
|
|
91
|
+ temp = lista[n]
|
|
92
|
+ lista[n] = lista[n - interval]
|
|
93
|
+ lista[n - interval] = temp
|
|
94
|
+ n -= interval
|
|
95
|
+ # print(lista)
|
|
96
|
+ # Update index to continue comparison with the next value in the sub array
|
|
97
|
+ j += interval
|
|
98
|
+ interval //= 2
|
|
99
|
+ # print(lista)
|
63
|
100
|
return lista
|
64
|
101
|
|
65
|
102
|
maxValor=1000 #define el valor maximo de los elementos de la lista
|
|
@@ -102,3 +139,4 @@ print "MergeSort " + str(acumulaMerge/veces) + " segundos"
|
102
|
139
|
print "HeapSort " + str(acumulaHeap/veces) + " segundos"
|
103
|
140
|
print "QuickSort " + str(acumulaQuick/veces) + " segundos"
|
104
|
141
|
print "ShellSort " + str(acumulaShell/veces) + " segundos"
|
|
142
|
+
|