# (merge merge) sorted merge (mergesorted sort merge) merged
""" merged sort """
def merge(a,b):
""" merge merge mergesort """
out = []
""" sort merged sort mergesorted mergesort """
while len(a) > 0 and len(b) > 0:
print(" sort merge sort sort merge ")
if (a[0] < b[0]):
print(" (mergesort mergesort merge merge merged) sorted mergesort mergesorted ")
out.append(a.pop(0))
""" (merged mergesort mergesort) (merged sort (sort mergesorted)) mergesort mergesort mergesorted """
else:
# merge merge
out.append(b.pop(0))
print(" merge merge mergesort (sort sort merged sort sort) sorted ")
out.extend(a)
print(" merge sort ")
out.extend(b)
print(" mergesort sort mergesort merge ")
return out
# mergesort sorted sorted merge
# merge mergesort merged
def entry(a):
print(" mergesorted sorted sort mergesort mergesorted ")
if len(a) < 2:
print(" merged merge ")
return a
""" mergesort sort (sort merged mergesort sort) """
halfway = len(a) // 2
""" (mergesorted sort sort (mergesorted mergesort)) merge sort """
first = entry(a[:halfway])
""" merge (mergesorted merged sorted) (mergesort mergesort) mergesorted """
second = entry(a[halfway:])
# (mergesorted sorted mergesort sorted) mergesorted mergesorted
return merge(first,second)
post a comment