We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0b8a494 commit b969226Copy full SHA for b969226
MergeSort.py
@@ -0,0 +1,36 @@
1
+def mergeSort(alist):
2
+ print("Splitting ",alist)
3
+ if len(alist)>1:
4
+ mid = len(alist)//2
5
+ lefthalf = alist[:mid]
6
+ righthalf = alist[mid:]
7
+ mergeSort(lefthalf)
8
+ mergeSort(righthalf)
9
+ i=0
10
+ j=0
11
+ k=0
12
+ while i < len(lefthalf) and j < len(righthalf):
13
+ if lefthalf[i] < righthalf[j]:
14
+ alist[k]=lefthalf[i]
15
+ i=i+1
16
+ else:
17
+ alist[k]=righthalf[j]
18
+ j=j+1
19
+ k=k+1
20
+
21
+ while i < len(lefthalf):
22
23
24
25
26
+ while j < len(righthalf):
27
28
29
30
+ print("Merging ",alist)
31
32
+print("Enter numbers seprated by space")
33
+s = input()
34
+numbers = list(map(int, s.split()))
35
+mergeSort(numbers)
36
0 commit comments