Skip to content

Commit

Permalink
Merge pull request #116 from achudinovskyh/python-merge-sort
Browse files Browse the repository at this point in the history
added MergeSort on Python
  • Loading branch information
fineanmol committed Oct 30, 2020
2 parents c9defc5 + 5de7022 commit 9639808
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ <h1 class="animated rubberBand delay-4s">Contributors</h1>
<a class="box-item" href="https://github.com/ameygangwal"><span>Amey</span></a>
<a class="box-item" href="https://github.com/JoaoJesus94"><span>João Jesus</span></a>
<a class="box-item" href="https://github.com/alvalle09"><span>Alfredo Valle</span></a>
<a class="box-item" href="https://github.com/achudinovskyh"><span>Andrew Chudinovskyh</span></a>
<a class="box-item" href="https://github.com/ydegtyar"><span>Yuriy Degtyar</span></a>


<!--
Add here
format : <a class="box-item" href="https://github.com/<your-username>"><span>Your Name</span></a>
Expand Down
33 changes: 33 additions & 0 deletions merge_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

def merge_sort(numbers):
if len(numbers) > 1:
mid = len(numbers) // 2
left_half = numbers[:mid]
right_half = numbers[mid:]
merge_sort(left_half)
merge_sort(right_half)
i = j = k = 0

while i < len(left_half) and j < len(right_half):
if left_half[i] < right_half[j]:
numbers[k] = left_half[i]
i = i + 1
else:
numbers[k] = right_half[j]
j = j + 1
k = k + 1

while i < len(left_half):
numbers[k] = left_half[i]
i = i + 1
k = k + 1

while j < len(right_half):
numbers[k] = right_half[j]
j = j + 1
k = k + 1


numbers = [39, 72, 64, 89, 38, 25, 27, 65, 91, 8]
merge_sort(numbers)
print(numbers)

0 comments on commit 9639808

Please sign in to comment.