Browse Source

Adding el cambio que el profe dijo.

diegoaperez 2 years ago
parent
commit
d9bf55303b
1 changed files with 19 additions and 13 deletions
  1. 19
    13
      sorting.py

+ 19
- 13
sorting.py View File

@@ -56,23 +56,29 @@ acumulaQuick=0 	#variable para acumular el tiempo de ejecucion del quicksort
56 56
 acumulaShell=0 	#variable para acumular el tiempo de ejecucion del shellsort
57 57
 
58 58
 for i in range(veces):
59
-	lista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar
59
+        lista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar
60 60
 
61
-	t1 = time.clock() 				#seteamos el tiempo al empezar
62
-	mergeSort(lista) 				#ejecutamos el algoritmo mergeSort
63
-	acumulaMerge+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
61
+        # creamos copias de la lista para cada algoritmo
62
+        listaMerge = lista[:]
63
+        listaHeap = lista[:]
64
+        listaQuick = lista[:]
65
+        listaShell = lista[:]
64 66
 
65
-	t1 = time.clock()				#seteamos el tiempo al empezar
66
-	heapSort(lista)					#ejecutamos el algoritmo heapSort
67
-	acumulaHeap+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
67
+        t1 = time.clock()                               #seteamos el tiempo al empezar
68
+        mergeSort(listaMerge)                           #ejecutamos el algoritmo mergeSort
69
+        acumulaMerge+=time.clock()-t1   #acumulamos el tiempo de ejecucion
68 70
 
69
-	t1 = time.clock()				#seteamos el tiempo al empezar
70
-	quickSort(lista)				#ejecutamos el algoritmo quickSort
71
-	acumulaQuick+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
71
+        t1 = time.clock()                               #seteamos el tiempo al empezar
72
+        heapSort(listaHeap)                                     #ejecutamos el algoritmo heapSort
73
+        acumulaHeap+=time.clock()-t1    #acumulamos el tiempo de ejecucion
72 74
 
73
-	t1 = time.clock()				#seteamos el tiempo al empezar
74
-	shellSort(lista)				#ejecutamos el algoritmo shellSort
75
-	acumulaShell+=time.clock()-t1 	#acumulamos el tiempo de ejecucion
75
+        t1 = time.clock()                               #seteamos el tiempo al empezar
76
+        quickSort(listaQuick)                           #ejecutamos el algoritmo quickSort
77
+        acumulaQuick+=time.clock()-t1   #acumulamos el tiempo de ejecucion
78
+
79
+        t1 = time.clock()                               #seteamos el tiempo al empezar
80
+        shellSort(listaShell)                           #ejecutamos el algoritmo shellSort
81
+        acumulaShell+=time.clock()-t1   #acumulamos el tiempo de ejecucion
76 82
 
77 83
 #imprimos los resultados
78 84
 print "Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista)