Skip to content

Commit 7ca8f73

Browse files
authored
Merge pull request Aishanipach#22 from proPrateekSahu/main
A Python Project which sorts the array using merger sort (Implemented the algorithm in python)
2 parents 7465b90 + 5c2515b commit 7ca8f73

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

MergeSort.py

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Feel free to add basic python scripts/programs that helped you learn python. I h
3535
18. [aritmetic median, biggest number and lowest number](https://github.com/arnavvgupta/functionMaxMinMedian.py)
3636
19. [Insertion Sort](https://github.com/musaibbatghar/Beginners-Python-Projects/blob/main/Insertion_Sort.py) - [Musaib Batghar](https://github.com/musaibbatghar)
3737
20. [Snake game](https://github.com/Aishanipach/Beginners-Python-Projects/compare/main...meanshkumar:Beginners-Python-Projects:main?expand=1)- [Ansh Kumar](https://github.com/meanshkumar)
38+
21. [Merge_Sort](https://github.com/proPrateekSahu/Beginners-Python-Projects/blob/main/MergeSort.py) - [Prateek Kumar Sahu](https://github.com/proPrateekSahu)

0 commit comments

Comments
 (0)