Browse Source

Commit Merge.

diegoaperez 3 years ago
parent
commit
e8dc73fc59
1 changed files with 8 additions and 42 deletions
  1. 8
    42
      sorting.py

+ 8
- 42
sorting.py View File

11
 import time
11
 import time
12
 
12
 
13
 def mergeSort(lista):
13
 def mergeSort(lista):
14
-        #Camila Vazquez Rodriguez 
14
+        #Camila Vazquez Rodriguez
15
 	#definan el algoritmo de ordenamiento mergesort
15
 	#definan el algoritmo de ordenamiento mergesort
16
         if len(lista) > 1:
16
         if len(lista) > 1:
17
                 mid = len(lista)//2
17
                 mid = len(lista)//2
33
                         lista[k] = R[j]
33
                         lista[k] = R[j]
34
                         j += 1
34
                         j += 1
35
                 k += 1
35
                 k += 1
36
- 
36
+
37
         while i < len(L):
37
         while i < len(L):
38
                 lista[k] = L[i]
38
                 lista[k] = L[i]
39
                 i += 1
39
                 i += 1
40
                 k += 1
40
                 k += 1
41
- 
41
+
42
         while j < len(R):
42
         while j < len(R):
43
                 lista[k] = R[j]
43
                 lista[k] = R[j]
44
                 j += 1
44
                 j += 1
45
                 k += 1
45
                 k += 1
46
-                
46
+
47
         return lista
47
         return lista
48
 
48
 
49
 def heapSort(lista):
49
 def heapSort(lista):
106
 def shellSort(lista):
106
 def shellSort(lista):
107
 	#definan el algoritmo de ordenamiento shellsort
107
 	#definan el algoritmo de ordenamiento shellsort
108
 
108
 
109
-	#El algoritmo compara elementos de una lista 
109
+	#El algoritmo compara elementos de una lista
110
 	#que tienen una distancia fija entre ellos, la
110
 	#que tienen una distancia fija entre ellos, la
111
-	#differencia en distancia se minimiza por cada 
111
+	#differencia en distancia se minimiza por cada
112
 	#iterazion del algoritmo
112
 	#iterazion del algoritmo
113
 
113
 
114
 	num = int(len(lista))
114
 	num = int(len(lista))
117
 	while dif > 0:
117
 	while dif > 0:
118
 		for i in range(int(dif),int(num)):
118
 		for i in range(int(dif),int(num)):
119
 			a = lista[i]
119
 			a = lista[i]
120
-			j = i 
120
+			j = i
121
 
121
 
122
-			#por cada intervalo se reorganizara los elementos 
122
+			#por cada intervalo se reorganizara los elementos
123
 			#si se cumple la declaracion dentro del while loop
123
 			#si se cumple la declaracion dentro del while loop
124
 			while j >= dif and lista[int(j - dif)] > a:
124
 			while j >= dif and lista[int(j - dif)] > a:
125
 				lista[int(j)] = lista[int(j - dif)]
125
 				lista[int(j)] = lista[int(j - dif)]
140
 acumulaShell=0 	#variable para acumular el tiempo de ejecucion del shellsort
140
 acumulaShell=0 	#variable para acumular el tiempo de ejecucion del shellsort
141
 
141
 
142
 for i in range(veces):
142
 for i in range(veces):
143
-<<<<<<< HEAD
144
-    lista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar
145
-
146
-    # creamos copias de la lista para cada algoritmo
147
-    listaMerge = lista[:]
148
-    listaHeap = lista[:]
149
-    listaQuick = lista[:]
150
-    listaShell = lista[:]
151
-
152
-    t1 = time.clock()  #seteamos el tiempo al empezar
153
-    mergeSort(listaMerge)  #ejecutamos el algoritmo mergeSort
154
-    acumulaMerge+=time.clock()-t1  #acumulamos el tiempo de ejecucion
155
-
156
-    t1 = time.clock()  #seteamos el tiempo al empezar
157
-    heapSort(listaHeap)  #ejecutamos el algoritmo heapSort
158
-    acumulaHeap+=time.clock()-t1 #acumulamos el tiempo de ejecucion
159
-
160
-    t1 = time.clock()  #seteamos el tiempo al empezar
161
-    quickSort(listaQuick)  #ejecutamos el algoritmo quickSort
162
-    acumulaQuick+=time.clock()-t1  #acumulamos el tiempo de ejecucion
163
-
164
-    t1 = time.clock()  #seteamos el tiempo al empezar
165
-    shellSort(listaShell)  #ejecutamos el algoritmo shellSort
166
-    acumulaShell+=time.clock()-t1  #acumulamos el tiempo de ejecucion
167
-
168
-#imprimos los resultados
169
-print "Promedio de tiempo de ejecucion de "+ str(veces) +" listas de largo " + str(largoLista)
170
-print "MergeSort " + str(acumulaMerge/veces) + " segundos"
171
-print "HeapSort " + str(acumulaHeap/veces) + " segundos"
172
-print "QuickSort " + str(acumulaQuick/veces) + " segundos"
173
-print "ShellSort " + str(acumulaShell/veces) + " segundos"
174
-=======
175
 	lista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar
143
 	lista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar
176
 
144
 
177
 	t1 = time.clock() 				#seteamos el tiempo al empezar
145
 	t1 = time.clock() 				#seteamos el tiempo al empezar
196
 print ("HeapSort " + str(acumulaHeap/veces) + " segundos")
164
 print ("HeapSort " + str(acumulaHeap/veces) + " segundos")
197
 print ("QuickSort " + str(acumulaQuick/veces) + " segundos")
165
 print ("QuickSort " + str(acumulaQuick/veces) + " segundos")
198
 print ("ShellSort " + str(acumulaShell/veces) + " segundos")
166
 print ("ShellSort " + str(acumulaShell/veces) + " segundos")
199
-
200
->>>>>>> ae9a1771cc651ae782615bb83aee73d658f88b39