Permalink
Cannot retrieve contributors at this time
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?
Guessuing_Game/Q2a_TCA
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (27 sloc)
1.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |