Skip to content

Commit 4b20678

Browse files
authored
Merge pull request argonautica#39 from johnmaf21/master
Added merge sort in python
2 parents 397d5b1 + 3ab4502 commit 4b20678

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Python/MergeSort.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def mergeSort(list):
2+
3+
if len(list) > 1:
4+
midPointer = len(list) // 2
5+
left = list[:midPointer]
6+
right = list[midPointer:]
7+
8+
mergeSort(left)
9+
mergeSort(right)
10+
11+
i = 0
12+
j = 0
13+
k = 0
14+
15+
while (i < len(left)) and (j < len(right)):
16+
if left[i] < right[j]:
17+
list[k] = left[i]
18+
i += 1
19+
else:
20+
list[k] = right[j]
21+
j += 1
22+
k += 1
23+
24+
while i < len(left):
25+
list[k] = left[i]
26+
i += 1
27+
k += 1
28+
29+
while j < len(right):
30+
list[k] = right[j]
31+
j += 1
32+
k += 1

0 commit comments

Comments
 (0)