File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change @@ -35,3 +35,4 @@ Feel free to add basic python scripts/programs that helped you learn python. I h
35
35
18 . [ aritmetic median, biggest number and lowest number] ( https://github.com/arnavvgupta/functionMaxMinMedian.py )
36
36
19 . [ Insertion Sort] ( https://github.com/musaibbatghar/Beginners-Python-Projects/blob/main/Insertion_Sort.py ) - [ Musaib Batghar] ( https://github.com/musaibbatghar )
37
37
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 )
You can’t perform that action at this time.
0 commit comments