Skip to content

Instantly share code, notes, and snippets.

@sahid
Last active December 13, 2015 20:48
Show Gist options
  • Select an option

  • Save sahid/4972596 to your computer and use it in GitHub Desktop.

Select an option

Save sahid/4972596 to your computer and use it in GitHub Desktop.
Insertion Sort in Python
def isort(A):
if len(A) <= 1: return A
i = 1
while i < len(A):
k = A[i]
j = i - 1
while j >= 0 and A[j] > k:
A[j+1] = A[j]
j -= 1
A[j+1] = k
i += 1
return A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment