Skip to content

Instantly share code, notes, and snippets.

@zedr
Last active December 11, 2016 13:46
Show Gist options
  • Save zedr/3fa39e314d58f4f141e53bbba874cb2a to your computer and use it in GitHub Desktop.
Save zedr/3fa39e314d58f4f141e53bbba874cb2a to your computer and use it in GitHub Desktop.
Algorithm: insertion sort
# Complexity: O(n^2)
def sort(arr):
l = len(arr)
if l > 1:
for ldx in range(l):
idx = ldx - 1
key = arr[ldx]
while idx > -1 and arr[idx] > key:
arr[idx + 1] = arr[idx]
idx -= 1
arr[idx + 1] = key
return arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment