I'm trying to create an insertion sort program in python with no built in functions. The only problem is that my program will only sort the first item in a list. What am I doing wrong?
My sort
def insertionsort(list1):
for index in range(len(list1)):
value = list1[index]
position = index
while position > 0 and list1[position-1] > value:
list1[position]=list1[position-1]
position = position-1
list1[position] = value
return(list1)
Example Output
List = [3,1,5,2]
Output = [1,3,5,2]