forked from argonautica/sorting-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeSort.py
More file actions
32 lines (26 loc) · 710 Bytes
/
MergeSort.py
File metadata and controls
32 lines (26 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def mergeSort(list):
if len(list) > 1:
midPointer = len(list) // 2
left = list[:midPointer]
right = list[midPointer:]
mergeSort(left)
mergeSort(right)
i = 0
j = 0
k = 0
while (i < len(left)) and (j < len(right)):
if left[i] < right[j]:
list[k] = left[i]
i += 1
else:
list[k] = right[j]
j += 1
k += 1
while i < len(left):
list[k] = left[i]
i += 1
k += 1
while j < len(right):
list[k] = right[j]
j += 1
k += 1