|
@@ -109,13 +109,43 @@ def quickSort(lista):
|
109
|
109
|
lista = left + [lista[current_position]] + right
|
110
|
110
|
return lista
|
111
|
111
|
|
|
112
|
+'''
|
|
113
|
+ This algorithm was taken from: https://www.programiz.com/dsa/shell-sort
|
|
114
|
+ and was adapted in order to work for this assigment.
|
|
115
|
+'''
|
|
116
|
+
|
|
117
|
+'''
|
|
118
|
+ This algorithm was taken from: https://www.programiz.com/dsa/shell-sort
|
|
119
|
+ and was adapted in order to work for this assigment.
|
|
120
|
+'''
|
|
121
|
+
|
112
|
122
|
def shellSort(lista):
|
113
|
|
-
|
114
|
|
- return lista
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+ n = len(lista)
|
|
127
|
+ gap = n // 2
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+ while gap > 0:
|
|
131
|
+ for i in range(gap, n):
|
|
132
|
+ temp = lista[i]
|
|
133
|
+ j = i
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+ while j >= gap and lista[j - gap] > temp:
|
|
138
|
+ lista[j] = lista[j - gap]
|
|
139
|
+ j -= gap
|
|
140
|
+
|
|
141
|
+ lista[j] = temp
|
|
142
|
+ gap = gap // 2
|
|
143
|
+
|
|
144
|
+ return lista
|
115
|
145
|
|
116
|
146
|
maxValor=1000
|
117
|
|
-largoLista=1000
|
118
|
|
-veces=100
|
|
147
|
+largoLista=1000
|
|
148
|
+veces=100
|
119
|
149
|
|
120
|
150
|
acumulaMerge=0
|
121
|
151
|
acumulaHeap=0
|
|
@@ -131,17 +161,17 @@ for i in range(veces):
|
131
|
161
|
t1 = time.process_time()
|
132
|
162
|
mergeSort(mergelista,0,len(mergelista)-1)
|
133
|
163
|
acumulaMerge+=time.process_time() - t1
|
134
|
|
- print(mergelista)
|
|
164
|
+
|
135
|
165
|
|
136
|
166
|
t1 = time.process_time()
|
137
|
167
|
heapSort(heaplista)
|
138
|
168
|
acumulaHeap+=time.process_time() - t1
|
139
|
|
- print(heaplista)
|
|
169
|
+
|
140
|
170
|
|
141
|
171
|
t1 = time.process_time()
|
142
|
172
|
quickresult = quickSort(quicklista)
|
143
|
173
|
acumulaQuick+=time.process_time() - t1
|
144
|
|
- print(quickresult)
|
|
174
|
+ print(quicklista)
|
145
|
175
|
|
146
|
176
|
t1 = time.process_time()
|
147
|
177
|
shellSort(searchlista)
|