Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mergesort(seq):
- mid=len(seq)//2
- lft, rgt = seq[:mid], seq[mid:]
- if len(lft) > 1: lft = mergesort(lft)
- if len(rgt) > 1: rgt = mergesort(rgt)
- res=[]
- while lft and rgt:
- if lft[-1] >= rgt[-1]:
- res.append(lft.pop())
- else:
- res.append(rgt.pop())
- res.reverse()
- return (lft or rgt) + res
- a=[1,4,2,3,4,21,2,3,1]
- print mergesort(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement