Update insertionsort.md
This commit is contained in:
@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user