diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index fb509aa8237d..e8e7ac5a1565 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -74,7 +74,7 @@ def bubble_sort_iterative[T: Comparable](collection: list[T]) -> list[T]: for i in reversed(range(length)): swapped = False for j in range(i): - if collection[j] > collection[j + 1]: + if collection[j + 1] < collection[j]: swapped = True collection[j], collection[j + 1] = collection[j + 1], collection[j] if not swapped: @@ -143,7 +143,7 @@ def bubble_sort_recursive[T: Comparable](collection: list[T]) -> list[T]: length = len(collection) swapped = False for i in range(length - 1): - if collection[i] > collection[i + 1]: + if collection[i + 1] < collection[i]: collection[i], collection[i + 1] = collection[i + 1], collection[i] swapped = True