我如何使用递归来实现这一点,它会更有效吗?
我的代码:
def insertionSort(array):
'''(list) - > list
Returns a sorted list of integers by implementing
the insertion sort which returns numbers in array from
least to greatest
'''
for i in range(1, len(array)):
if array[i-1] > array[i]: #Finds a number out of place
temp = array[i]
for a in range(0,i):
if temp < array[a]:
array.insert(a,temp)
del array[i+1]
break
return array