Files
30-seconds-of-code/test/insertion_sort/insertion_sort.py
Rohit Tanwar 385bf72a3e readme-script
2018-02-20 22:42:11 +05:30

9 lines
215 B
Python

def insertionsort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key