Skip to content

Instantly share code, notes, and snippets.

@richardbwest
Created November 9, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardbwest/ece6d6e0c624f41fc3009e19633bf411 to your computer and use it in GitHub Desktop.
Save richardbwest/ece6d6e0c624f41fc3009e19633bf411 to your computer and use it in GitHub Desktop.
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