Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
def Msort(input1): # delcaring the funtion
if len(input1) > 1:
middle = len(input1)//2 #finding the middle of the list
l = input1[:middle] # dividing into two lists
r = input1[middle:]
Msort(l) # Sorting the fisrt list l
Msort(r) # Sorting the second list r
i = j = x = 0
while i < len(l) and j < len(r): # adding the values to the another list
if l[i] < r[j]:
input1[x] = l[i]
i += 1
else:
input1[x] = r[j]
j += 1
x += 1
while i < len(l): #checking the first list if its empty
input1[x] = l[i]
i += 1
x += 1
while j < len(r): #checking the second list if its empty
input1[x] = r[j]
j += 1
x += 1
return input1
input1 = [12, 11, 13, 5, 6, 7] # input list
print(Msort(input1)) #output list