|
@@ -22,7 +22,39 @@ def quickSort(lista):
|
22
|
22
|
return lista
|
23
|
23
|
|
24
|
24
|
def shellSort(lista):
|
25
|
|
-
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ interval = len(lista) // 2
|
|
30
|
+ while interval > 0:
|
|
31
|
+
|
|
32
|
+ for i in range(0, interval):
|
|
33
|
+
|
|
34
|
+ sortedIndex = i
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+ j = i
|
|
38
|
+ while j + interval < len(lista):
|
|
39
|
+ if lista[j] > lista[j + interval]:
|
|
40
|
+
|
|
41
|
+ temp = lista[j]
|
|
42
|
+ lista[j] = lista[j + interval]
|
|
43
|
+ lista[j + interval] = temp
|
|
44
|
+
|
|
45
|
+ n = j
|
|
46
|
+
|
|
47
|
+ while n - interval >= 0 and lista[n] < lista[n - interval]:
|
|
48
|
+
|
|
49
|
+ temp = lista[n]
|
|
50
|
+ lista[n] = lista[n - interval]
|
|
51
|
+ lista[n - interval] = temp
|
|
52
|
+ n -= interval
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ j += interval
|
|
56
|
+ interval //= 2
|
|
57
|
+
|
26
|
58
|
return lista
|
27
|
59
|
|
28
|
60
|
maxValor=1000
|
|
@@ -37,26 +69,26 @@ acumulaShell=0 #variable para acumular el tiempo de ejecucion del shellsort
|
37
|
69
|
for i in range(veces):
|
38
|
70
|
lista = [randint(0,maxValor) for r in range(largoLista)]
|
39
|
71
|
|
40
|
|
- t1 = time.clock()
|
41
|
|
- mergeSort(lista)
|
42
|
|
- acumulaMerge+=time.clock()-t1
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
43
|
75
|
|
44
|
|
- t1 = time.clock()
|
45
|
|
- heapSort(lista)
|
46
|
|
- acumulaHeap+=time.clock()-t1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
47
|
83
|
|
48
|
|
- t1 = time.clock()
|
49
|
|
- quickSort(lista)
|
50
|
|
- acumulaQuick+=time.clock()-t1
|
51
|
|
-
|
52
|
|
- t1 = time.clock()
|
53
|
|
- shellSort(lista)
|
54
|
|
- acumulaShell+=time.clock()-t1
|
|
84
|
+ t1 = time.perf_counter()
|
|
85
|
+ shellSort(lista)
|
|
86
|
+ acumulaShell+=time.perf_counter()-t1
|
55
|
87
|
|
56
|
88
|
|
57
|
|
-print "Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista)
|
58
|
|
-print "MergeSort " + str(acumulaMerge/veces) + " segundos"
|
59
|
|
-print "HeapSort " + str(acumulaHeap/veces) + " segundos"
|
60
|
|
-print "QuickSort " + str(acumulaQuick/veces) + " segundos"
|
61
|
|
-print "ShellSort " + str(acumulaShell/veces) + " segundos"
|
|
89
|
+print ("Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+print ("ShellSort " + str(acumulaShell/veces) + " segundos")
|
62
|
94
|
|