Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys
- def merge(p, q):
- s = []
- while 0 < len(p) and 0 < len(q):
- a = p[0]
- b = q[0]
- if a <= b:
- s.append(a)
- p.pop(0)
- else:
- s.append(b)
- q.pop(0)
- if 0 < len(p):
- s.extend(p)
- elif 0 < len(q):
- s.extend(q)
- return s
- def mergesort(a):
- n = len(a)
- if n <= 1:
- return a
- return merge(mergesort(a[:n // 2]), mergesort(a[n // 2:]))
- a = list(map(int, sys.argv[1:]))
- print(a)
- print(mergesort(a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement