I'm trying to write a recursive selection sort, and I'm really confused, and its really hard to be to track why this doesn't work. If anyone could tell me where the problem is, that would be great!
Here's my code
def selectionSortRecursive(lis, minIndex = 0):
if minIndex - 1 == len(lis):
return lis
minValueIndex = minIndex #Assigns the very first item in the list as the minimum value index
for i in range (minIndex + 1, len(lis)):
if lis[i] < lis[minValueIndex]: #if any item is less than min value, its index gets assigned the minimum value
minValueIndex = i
lis[minIndex], lis[minValueIndex] = lis[minValueIndex], lis[minIndex] #After you go through the list, you switch the smallest item into the minimum index, which starts off being 0
lis = selectionSortRecursive(lis, minIndex+1) #now we're gonna sort the list at the next min
return lis
Please try this modification: