diff --git a/snippets/insertionsort.md b/snippets/insertionsort.md index bc5f9747c..ce5a11ec1 100644 --- a/snippets/insertionsort.md +++ b/snippets/insertionsort.md @@ -1,5 +1,23 @@ -### Insertion Sort +## Insertion Sort +## Implementation +```python +arr = [] # list to sort + + +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 +``` + + +### Example ```python arr = [7,4,9,2,6,3]