Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # algorithm http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/mergeSort.htm
- def msort2(x):
- if len(x) < 2:
- return x
- result = [] # moved!
- mid = int(len(x)/2)
- y = msort2(x[:mid])
- z = msort2(x[mid:])
- while (len(y) > 0) and (len(z) > 0):
- if y[0] > z[0]:
- result.append(z[0])
- z.pop(0)
- else:
- result.append(y[0])
- y.pop(0)
- result += y
- result += z
- return result
Advertisement
Add Comment
Please, Sign In to add comment