Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Nov 29, 2020
Embed
What would you like to do?
def insertion_sort(array):
for i in range(1, len(array)):
key = array[i]
j = i - 1
while j >= 0 and key < array[j]:
array[j + 1] = array[j]
j-=1
array[j + 1] = key
array = [34, 56, 76, 34, 23, 65]
insertion_sort(array)
print("Sorted array using Insertion Sort algorithm : ")
for i in range(len(array)):
print(array[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment