I want to sort the array in ascending order using recursive insertion sort. This works until idx<len(arr)
but the sorting isn't finished there. What am I missing?
Given is the code I wrote:
def insertionSort(arr, idx):
i=idx
if idx<len(arr):
if arr[idx]<arr[idx-1]:
arr[idx], arr[idx-1]=arr[idx-1], arr[idx]
insertionSort(arr, idx + 1)
return arr
print(insertionSort([3,4,1], 1))
The output is [3,1,4], but I want it to sort into [1,3,4]