Created
October 1, 2021 12:25
-
-
Save ohaval/b3ce94401d1a111ddf7f4f97c1e28776 to your computer and use it in GitHub Desktop.
The Insertion sort algorithm simple and readable implementation in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
def insertion_sort(lst: List[int]) -> None: | |
"""The Insertion sort algorithm. | |
The sorted list is placed in place. | |
Wikipedia: https://en.wikipedia.org/wiki/Insertion_sort | |
""" | |
for i in range(1, len(lst)): | |
for j in range(i): | |
if lst[i] < lst[j]: | |
lst.insert(j, lst.pop(i)) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment