Create insertionsort.md

This commit is contained in:
Meet Zaveri
2018-02-20 14:53:02 +05:30
committed by GitHub
parent c5c0c8c2b9
commit 6f9a7ac8bd

19
snippets/insertionsort.md Normal file
View File

@ -0,0 +1,19 @@
### Insertion Sort
```py
arr = [7,4,9,2,6,3]
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
insertionsort(arr)
print('modified %s' %arr) # modified [2, 3, 4, 6, 7, 9]
```