|
@@ -10,9 +10,60 @@ from random import randint
|
10
|
10
|
import time
|
11
|
11
|
|
12
|
12
|
def mergeSort(lista):
|
13
|
|
-
|
14
|
|
- return lista
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+ if len(lista) > 1:
|
|
18
|
+
|
|
19
|
+ middle = len(lista)//2
|
|
20
|
+
|
|
21
|
+ Left = mergeSort(lista[:middle])
|
|
22
|
+
|
|
23
|
+ Right = mergeSort(lista[middle:])
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+ return merge(Right, Left, lista)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ return lista
|
|
30
|
+
|
|
31
|
+def merge(Right, Left, lista):
|
|
32
|
+
|
|
33
|
+ i = 0
|
|
34
|
+ j = 0
|
|
35
|
+ k = 0
|
15
|
36
|
|
|
37
|
+
|
|
38
|
+ while i < len(Left) and j < len(Right):
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+ if Left[i] < Right[j]:
|
|
42
|
+ lista[k] = Left[i]
|
|
43
|
+ i += 1
|
|
44
|
+ k += 1
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+ else:
|
|
48
|
+ lista[k] = Right[j]
|
|
49
|
+ j += 1
|
|
50
|
+ k += 1
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ while i < len(Left):
|
|
54
|
+ lista[k] = Left[i]
|
|
55
|
+ i += 1
|
|
56
|
+ k += 1
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ while j < len(Right):
|
|
60
|
+ lista[k] = Right[j]
|
|
61
|
+ j += 1
|
|
62
|
+ k += 1
|
|
63
|
+
|
|
64
|
+ return lista
|
|
65
|
+
|
|
66
|
+
|
16
|
67
|
def heapSort(lista):
|
17
|
68
|
|
18
|
69
|
return lista
|