diff --git a/sorts/merge_sort_fastest.py b/sorts/merge_sort_fastest.py index cb7359ce2..2e6249778 100644 --- a/sorts/merge_sort_fastest.py +++ b/sorts/merge_sort_fastest.py @@ -7,14 +7,15 @@ Worst Case Scenario : O(n) def merge_sort(LIST): start = [] end = [] - a = LIST[0] - b = LIST[-1] - while (LIST.index(a) == LIST.index(b) and len(LIST) <=2): + while LIST: a = min(LIST) b = max(LIST) start.append(a) end.append(b) - LIST.remove(a) - LIST.remove(b) + try: + LIST.remove(a) + LIST.remove(b) + except ValueError: + continue end.reverse() -return start + end + return (start + end)