From ba7b21ec041b504f4cbc9aaef7fcb12a27efd12b Mon Sep 17 00:00:00 2001 From: Alisha Date: Sat, 29 Apr 2017 01:04:08 +1000 Subject: [PATCH] Small mistake in sort/merge_sort.py array merge --- sort/merge_sort.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sort/merge_sort.py b/sort/merge_sort.py index 90c3bbe1f..cb736713c 100644 --- a/sort/merge_sort.py +++ b/sort/merge_sort.py @@ -26,14 +26,12 @@ def merge(left, right): else: arr.append(right[right_cursor]) right_cursor+=1 - # Add the left overs if there's any left to the result - if left: - arr.extend(left[left_cursor:]) - if right: - arr.extend(right[right_cursor:]) - return arr + # Add the left overs if there's any left to the result + for i in range(left_cursor,len(left)): + arr.append(left[i]) + for i in range(right_cursor,len(right)): + arr.append(right[i]) array = [1,5, 7,4,3,2,1,9,0,10,43,64] print(array) -print(merge_sort(array, 0, len(array)-1)) -print(array) +print(merge_sort(array))