-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathn143_repeat_program.py
More file actions
53 lines (34 loc) · 841 Bytes
/
Copy pathn143_repeat_program.py
File metadata and controls
53 lines (34 loc) · 841 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def merge(left, right):
a=[None]*(len(left)+ len(right))
i,j,k = 0,0,0
while i < len(left) and j < len(right):
if left[i] <= right[j]:
a[k] = left[i]
k = k+1
i= i+1
else:
a[k] = right[j]
k= k+1
j = j+1
if i < len(left):
while i < len(left):
a[k] = left[i]
i = i+1
k = k+1
if j < len(right):
while j < len(right):
a[k] = right[j]
j = j+1
k = k+1
return a
def merge_sort(a ):
mid = (len(a)) //2
if len(a) <= 1:
return a
left=merge_sort(a[:mid])
right = merge_sort(a[mid:])
d = merge(left,right)
return d
if __name__ =='__main__':
a= [7, 2, 1, 3, 8, 4, 9, 1, 2, 6]
print(merge_sort(a))