Created
October 1, 2021 12:20
-
-
Save ohaval/45cf041c26dfa87d50a787f482ede47b to your computer and use it in GitHub Desktop.
The Bubble 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 bubble_sort(lst: List[int]) -> None: | |
"""The Bubble sort algorithm. | |
The sorted list is placed in place. | |
Wikipedia: https://en.wikipedia.org/wiki/Bubble_sort | |
""" | |
for i in range(len(lst) - 1, 0, -1): | |
for j in range(i): | |
if lst[j] > lst[j + 1]: | |
lst[j], lst[j + 1] = lst[j + 1], lst[j] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment