Skip to content

Instantly share code, notes, and snippets.

@ohaval
Created October 1, 2021 12:20
Show Gist options
  • Save ohaval/45cf041c26dfa87d50a787f482ede47b to your computer and use it in GitHub Desktop.
Save ohaval/45cf041c26dfa87d50a787f482ede47b to your computer and use it in GitHub Desktop.
The Bubble sort algorithm simple and readable implementation in Python
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