Browse Source

sorting.py Camila

camila.vazquez1 3 years ago
parent
commit
815713a2f3
1 changed files with 33 additions and 1 deletions
  1. 33
    1
      sorting.py

+ 33
- 1
sorting.py View File

@@ -10,8 +10,40 @@ from random import randint
10 10
 import time
11 11
 
12 12
 def mergeSort(lista):
13
+        #Camila Vazquez 
13 14
 	#definan el algoritmo de ordenamiento mergesort
14
-	return lista
15
+        if len(lista) > 1:
16
+                mid = len(lista)//2
17
+                L = lista[:mid]
18
+                R = lista[mid:]
19
+
20
+                mergeSort(L)
21
+                mergeSort(R)
22
+
23
+                i = 0
24
+                j = 0
25
+                k = 0
26
+
27
+        while i < len(L) and j < len(R):
28
+                if L[i] <= R[j]:
29
+                        lista[k] = L[i]
30
+                        i += 1
31
+                else:
32
+                        lista[k] = R[j]
33
+                        j += 1
34
+                        k += 1
35
+ 
36
+        while i < len(L):
37
+                lista[k] = L[i]
38
+                i += 1
39
+                k += 1
40
+ 
41
+        while j < len(R):
42
+                lista[k] = R[j]
43
+                j += 1
44
+                k += 1
45
+                
46
+        return lista
15 47
 
16 48
 def heapSort(lista):
17 49
 	#definan el algoritmo de ordenamiento heapsort