|
@@ -19,6 +19,29 @@ def heapSort(lista):
|
19
|
19
|
|
20
|
20
|
def quickSort(lista):
|
21
|
21
|
#definan el algoritmo de ordenamiento quicksort
|
|
22
|
+ elements = len(lista)
|
|
23
|
+
|
|
24
|
+ #Base case
|
|
25
|
+ if elements < 2:
|
|
26
|
+ return lista
|
|
27
|
+
|
|
28
|
+ current_position = 0 #Position of the partitioning element
|
|
29
|
+
|
|
30
|
+ for i in range(1, elements): #Partitioning loop
|
|
31
|
+ if lista[i] <= lista[0]:
|
|
32
|
+ current_position += 1
|
|
33
|
+ temp = lista[i]
|
|
34
|
+ lista[i] = lista[current_position]
|
|
35
|
+ lista[current_position] = temp
|
|
36
|
+
|
|
37
|
+ temp = lista[0]
|
|
38
|
+ lista[0] = lista[current_position]
|
|
39
|
+ lista[current_position] = temp #Brings pivot to it's appropriate position
|
|
40
|
+
|
|
41
|
+ left = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot
|
|
42
|
+ right = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot
|
|
43
|
+
|
|
44
|
+ lista = left + [lista[current_position]] + right #Merging everything together
|
22
|
45
|
return lista
|
23
|
46
|
|
24
|
47
|
def shellSort(lista):
|
|
@@ -51,9 +74,9 @@ for i in range(veces):
|
51
|
74
|
print(heaplista) #desplegamos la lista
|
52
|
75
|
|
53
|
76
|
t1 = time.process_time() #tomamos el tiempo inicial
|
54
|
|
- quickSort(quicklista) #ejecutamos el algoritmo quickSort
|
|
77
|
+ quickresult = quickSort(quicklista) #ejecutamos el algoritmo quickSort
|
55
|
78
|
acumulaQuick+=time.process_time() - t1 #acumulamos el tiempo de ejecucion
|
56
|
|
- print(quicklista) #desplegamos la lista
|
|
79
|
+ print(quickresult) #desplegamos la lista
|
57
|
80
|
|
58
|
81
|
t1 = time.process_time() #tomamos el tiempo inicial
|
59
|
82
|
shellSort(searchlista) #ejecutamos el algoritmo shellSort
|