Guest User

Untitled

a guest
Nov 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. def merge_sort(list_struct=[]):
  2. """
  3. merge_sort
  4. as if there's not enough merge sorts in python out there
  5. """
  6. list_len = len(list_struct)
  7. if list_len <= 1:
  8. return list_struct
  9.  
  10. mid = list_len / 2
  11. left = list_struct[:mid]
  12. right = list_struct[mid:]
  13.  
  14. left = merge_sort(left)
  15. right = merge_sort(right)
  16. new_list_struct = []
  17.  
  18. while left and right:
  19. if left[0] < right[0]:
  20. new_list_struct.append(left.pop(0))
  21. else:
  22. new_list_struct.append(right.pop(0))
  23.  
  24. if left:
  25. new_list_struct.extend(left)
  26. if right:
  27. new_list_struct.extend(right)
  28.  
  29. return new_list_struct
Add Comment
Please, Sign In to add comment