-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMergeSort.py
37 lines (33 loc) · 998 Bytes
/
MergeSort.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def rank(alist):
n= len(alist)
if n>1:
if n%2==0:
half=int(n/2)
n1=alist[0:half]
n2=alist[half:n]
else:
half=int((n+1)/2)
n1 = alist[0:half]
n2 = alist[half:n]
rank(n1)
rank(n2)
i=0
j=0
k=0
while i<len(n1) and j<len(n2):
if n1[i]<n2[j]:
alist[k]=n1[i]
i=i+1
else:
alist[k]=n2[j]
j=j+1
k=k+1
while i< len(n1):
alist[k]=n1[i]
i=i+1
k=k+1
while j < len(n2):
alist[k] = n2[j]
j = j + 1
k = k + 1
print(alist)