Skip to content

Commit 876d5f7

Browse files
authored
Merge pull request keon#45 from alisha17/Small_mistake_in_sort/merge_sort.py_array_merge
Small mistake in sort/merge_sort.py array merge
2 parents de89258 + ba7b21e commit 876d5f7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

sort/merge_sort.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ def merge(left, right):
2626
else:
2727
arr.append(right[right_cursor])
2828
right_cursor+=1
29-
# Add the left overs if there's any left to the result
30-
if left:
31-
arr.extend(left[left_cursor:])
32-
if right:
33-
arr.extend(right[right_cursor:])
34-
return arr
29+
# Add the left overs if there's any left to the result
30+
for i in range(left_cursor,len(left)):
31+
arr.append(left[i])
32+
for i in range(right_cursor,len(right)):
33+
arr.append(right[i])
3534

3635
array = [1,5, 7,4,3,2,1,9,0,10,43,64]
3736
print(array)
38-
print(merge_sort(array, 0, len(array)-1))
39-
print(array)
37+
print(merge_sort(array))

0 commit comments

Comments
 (0)