Skip to content

Instantly share code, notes, and snippets.

@rishi93
Created September 23, 2015 11:26
Show Gist options
  • Select an option

  • Save rishi93/1c42cb1109000ea540fc to your computer and use it in GitHub Desktop.

Select an option

Save rishi93/1c42cb1109000ea540fc to your computer and use it in GitHub Desktop.
Insertion Sort
def insertionsort(arr):
for i in range(1,len(arr)):
val = arr[i]
j = i - 1
while j >= 0 and arr[j]>val:
arr[j+1] = arr[j]
j -= 1
arr[j+1] = val
print(arr)
arr = [54,26,93,17,77,31,44,55,20]
insertionsort(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment