Skip to content

Instantly share code, notes, and snippets.

@reterVision
Created January 12, 2014 05:32
Show Gist options
  • Save reterVision/cb2c67f8ef4eb26eda66 to your computer and use it in GitHub Desktop.
Save reterVision/cb2c67f8ef4eb26eda66 to your computer and use it in GitHub Desktop.
Insertion Sort
"""
Insertion Sort
"""
def insertion_sort(array):
i = 0
while i < len(array):
j = i
while j > 0 and array[j-1] > array[j]:
array[j], array[j-1] = array[j-1], array[j]
j -= 1
i += 1
return array
if __name__ == "__main__":
array = [7, 5, 3, 1, 2, 4, 9, 8, 6, 10]
print insertion_sort(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment