Skip to content

Instantly share code, notes, and snippets.

@richardbwest

richardbwest/Insertion Sort Secret

Created Nov 9, 2020
Embed
What would you like to do?
l = [7,11,3,1,2,5,6,9]
def insertion_sort(l):
for outer_index in range(1,len(l)):
current_item = l[outer_index]
inner_index = outer_index
while inner_index > 0 and l[inner_index-1] > current_item:
l[inner_index] = l[inner_index-1]
inner_index -= 1
l[inner_index] = current_item
insertion_sort(l)
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment