Tell us what’s happening:
I’ve tried various ways of copying a list and assigning it to array list such as
array = left_array.copy()
array.append(left_array)
or even simply
array = left_array
I’m not sure any other variations of this will work and can’t think of solutions outside of attempting to copy/add the left_array into array. I might be oversimplifying it, but I’d appreciate any guidance.
Your code so far
def merge_sort(array):
middle_point = len(array) // 2
left_part = array[:middle_point]
right_part = array[middle_point:]
merge_sort(left_part)
merge_sort(right_part)
left_array_index = 0
right_array_index = 0
sorted_index = 0
while left_array_index < len(left_part) and right_array_index < len(right_part):
if left_part[left_array_index] < right_part[right_array_index]:
array[sorted_index] = left_part[left_array_index]
left_array_index += 1
else:
array[sorted_index] = right_part[right_array_index]
right_array_index += 1
sorted_index += 1
# User Editable Region
while left_array_index < len(left_part):
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0
Challenge Information:
Learn Data Structures by Building the Merge Sort Algorithm - Step 18