mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create insertion_sort.py
This commit is contained in:
parent
52cba3f861
commit
28d28b817e
13
sorting/insertion_sort.py
Normal file
13
sorting/insertion_sort.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# author: bt3gl
|
||||||
|
|
||||||
|
def insertion_sort(lst):
|
||||||
|
|
||||||
|
for i in range(1, len(lst)):
|
||||||
|
current_index = i
|
||||||
|
|
||||||
|
while current_index > 0 and lst[current_index - 1] > lst[current_index]:
|
||||||
|
|
||||||
|
lst[current_index], lst[current_index - 1] = lst[current_index - 1], lst[current_index]
|
||||||
|
current_index -= 1
|
Loading…
x
Reference in New Issue
Block a user