So, I tried and get [1, 2, 3, 5, -4] but I want to get [3, 1, 2, 5, -4] as result instead; because I want to sort only from index 1 to index 4 (including start, excluding end; which mean only sorting from index 1 to index 3, leaving index 0 and 4 as it is) of the list
def insertionSort(the_list, start, end):
for mark in range(start, end):
temp = the_list[mark]
i = mark-1
while i >= 0 and the_list[i] > temp:
the_list[i+1] = the_list[i]
i -= 1
the_list[i+1] = temp
return the_list
print(insertionSort([3, 2, 5, 1, -4], 1, 4))
Can someone help me fix the code so I can get the result I want? Thank you.