From 7f4b240d1a9092f8e04257f26965b7bc3a4dac07 Mon Sep 17 00:00:00 2001 From: Harshil Date: Mon, 21 May 2018 10:21:33 +0200 Subject: [PATCH] Update merge_sort_fastest.py I have modified the code a little to make it work as expected! --- sorts/merge_sort_fastest.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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)