Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def merge_sort(list_struct=[]):
- """
- merge_sort
- as if there's not enough merge sorts in python out there
- """
- list_len = len(list_struct)
- if list_len <= 1:
- return list_struct
- mid = list_len / 2
- left = list_struct[:mid]
- right = list_struct[mid:]
- left = merge_sort(left)
- right = merge_sort(right)
- new_list_struct = []
- while left and right:
- if left[0] < right[0]:
- new_list_struct.append(left.pop(0))
- else:
- new_list_struct.append(right.pop(0))
- if left:
- new_list_struct.extend(left)
- if right:
- new_list_struct.extend(right)
- return new_list_struct
Add Comment
Please, Sign In to add comment