The principle of this sorting algorithm is simple: starting from a float list inlist to be sorted, the elements of inlist will be extracted one at a time, and placed into a new list outlist (originally empty) such that outlist always remain a sorted list.
This algorithm is supposed to go through every element in the list. However, it just stops half way.
def insertion_sort(inlist):
outlist = []
for i in inlist:
x = inlist.pop(0)
outlist.append(x)
return sorted(outlist)
print(insertion_sort([1,2,6,3,5,4]))
The output is [1,2,6] but i want the output to be [1,2,3,4,5,6] What is wrong with my code? Thank you so much for helping.