Procházet zdrojové kódy

Merge branch 'QuickSortJose' into sortingFinal

José C.S. Curet před 1 rokem
rodič
revize
03a702c7d1
2 změnil soubory, kde provedl 58 přidání a 18 odebrání
  1. 17
    0
      quicksort_log.txt
  2. 41
    18
      sorting.py

+ 17
- 0
quicksort_log.txt Zobrazit soubor

@@ -0,0 +1,17 @@
1
+commit e08cae0dd7f77de0b92b80bdca8785de5bb3003a
2
+Author: José C.S. Curet <45988719+curet@users.noreply.github.com>
3
+Date:   Tue Oct 4 12:44:18 2022 -0400
4
+
5
+    update from python2 to python3
6
+
7
+commit b541128ae04dfaa37439dcd85266f0e7777d2568
8
+Author: José C.S. Curet <45988719+curet@users.noreply.github.com>
9
+Date:   Tue Oct 4 12:43:51 2022 -0400
10
+
11
+    implement quicksort function
12
+
13
+commit bac07ff30082c86ad131ce569934a00b1509e3da
14
+Author: Héctor <hector@Hectors-MacBook-Pro.local>
15
+Date:   Tue Sep 13 12:45:58 2022 -0400
16
+
17
+    sorting.py

+ 41
- 18
sorting.py Zobrazit soubor

@@ -17,8 +17,31 @@ def heapSort(lista):
17 17
 	#definan el algoritmo de ordenamiento heapsort
18 18
 	return lista
19 19
 
20
-def quickSort(lista):
20
+"""
21
+Esta implementación de la función partition, relacionada a quicksort fue extraida de geeksforgeeks.org Oct 4, 2022
22
+https://www.geeksforgeeks.org/quick-sort/
23
+"""
24
+def partition(lista, low, high):
25
+	pivot = lista[high]
26
+	i = low - 1
27
+	for j in range(low, high):
28
+		if lista[j] <= pivot:
29
+			i = i + 1
30
+			(lista[i], lista[j]) = (lista[j], lista[i])
31
+	(lista[i + 1], lista[high]) = (lista[high], lista[i + 1])
32
+
33
+	return i + 1
34
+
35
+"""
36
+Esta implementación de quicksort fue extraida de geeksforgeeks.org Oct 4, 2022
37
+https://www.geeksforgeeks.org/quick-sort/
38
+"""
39
+def quickSort(lista, low, high):
21 40
 	#definan el algoritmo de ordenamiento quicksort
41
+	if low < high:
42
+		pi = partition(lista, low, high)
43
+		quickSort(lista, low, pi - 1)
44
+		quickSort(lista, pi + 1, high)
22 45
 	return lista
23 46
 
24 47
 def shellSort(lista):
@@ -40,25 +63,25 @@ for i in range(veces):
40 63
 	quicklista=list(mergelista)
41 64
 	searchlista=list(mergelista)
42 65
 
43
-	t1 = time.clock() 				#seteamos el tiempo al empezar
44
-	mergeSort(mergelista) 				#ejecutamos el algoritmo mergeSort
45
-	acumulaMerge+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
66
+	# t1 = time.time() 				#seteamos el tiempo al empezar
67
+	# mergeSort(mergelista) 				#ejecutamos el algoritmo mergeSort
68
+	# acumulaMerge+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
46 69
 	
47
-	t1 = time.clock()				#seteamos el tiempo al empezar
48
-	heapSort(heaplista)					#ejecutamos el algoritmo heapSort
49
-	acumulaHeap+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
70
+	# t1 = time.time()				#seteamos el tiempo al empezar
71
+	# heapSort(heaplista)					#ejecutamos el algoritmo heapSort
72
+	# acumulaHeap+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
50 73
 	
51
-	t1 = time.clock()				#seteamos el tiempo al empezar
52
-	quickSort(quicklista)				#ejecutamos el algoritmo quickSort
53
-	acumulaQuick+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
74
+	t1 = time.time()				#seteamos el tiempo al empezar
75
+	quickSort(quicklista, 0, len(quicklista) - 1)				#ejecutamos el algoritmo quickSort
76
+	acumulaQuick+=time.time()-t1 	#acumulamos el tiempo de ejecucion
54 77
 	
55
-	t1 = time.clock()				#seteamos el tiempo al empezar
56
-	shellSort(searchlista)				#ejecutamos el algoritmo shellSort
57
-	acumulaShell+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
78
+	# t1 = time.time()				#seteamos el tiempo al empezar
79
+	# shellSort(searchlista)				#ejecutamos el algoritmo shellSort
80
+	# acumulaShell+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
58 81
 
59 82
 #imprimos los resultados
60
-print "Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista)
61
-print "MergeSort " + str(acumulaMerge/veces) + " segundos"
62
-print "HeapSort " + str(acumulaHeap/veces) + " segundos"
63
-print "QuickSort " + str(acumulaQuick/veces) + " segundos"
64
-print "ShellSort " + str(acumulaShell/veces) + " segundos"
83
+print("Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista))
84
+# print("MergeSort " + str(acumulaMerge/veces) + " segundos")
85
+# print("HeapSort " + str(acumulaHeap/veces) + " segundos")
86
+print("QuickSort " + str(acumulaQuick/veces) + " segundos")
87
+# print("ShellSort " + str(acumulaShell/veces) + " segundos")