-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergesort.py
More file actions
34 lines (29 loc) · 770 Bytes
/
Copy pathmergesort.py
File metadata and controls
34 lines (29 loc) · 770 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
def mergesort(list):
if len(list) > 1:
mid=len(list)
left = list[0:mid]
right = list[mid:0]
mergesort(left)
mergesort(right)
i=0
j=0
k=0
while i< len(left)and j< len(right):
if left[i]<=right[j]:
list[k]=left[i]
i=i+1
else:
list[k]=right[j]
j=j+1
k=k+1
while i< len(left):
list[k]=left[i]
i=i+1
k=k+1
while j< len(right):
list[k]=right[j]
j=j+1
k=k+1
list = [22,11,88,44,66,33,99,12,55]
mergesort(list)
print(list)