I am practicing algorithms.
I don't understand why the below code is not working.
It is suppose to be merge sort.
Also I am confused on how to best debug this issue myself?
I don't understand why the below code is not working.
It is suppose to be merge sort.
Also I am confused on how to best debug this issue myself?
def ms(ls):
if len(ls)==1: #base case
return ls
else:
mid = len(ls)//2
l = ms(ls[:mid])
r = ms(ls[mid:])
nu=[] #return list
for x in l:
if len(r)==0:
nu.append(x)
elif x<r[0]:
nu.append(x)
else:
while x>=r[0]:
numss = r.pop(0)
#print(numss)
nu.append(numss)
if len(r)==0: break
if len(r)!=0: #if the r list is left, attach
for x in r:
nu.append(x)
return nu
