Skip to content

Commit 7f81fcd

Browse files
authored
fix: make bubble sort work with comparable items (#15448)
1 parent 3f0532a commit 7f81fcd

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎sorts/bubble_sort.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def bubble_sort_iterative[T: Comparable](collection: list[T]) -> list[T]:
7474
for i in reversed(range(length)):
7575
swapped = False
7676
for j in range(i):
77-
if collection[j] > collection[j + 1]:
77+
if collection[j + 1] < collection[j]:
7878
swapped = True
7979
collection[j], collection[j + 1] = collection[j + 1], collection[j]
8080
if not swapped:
@@ -143,7 +143,7 @@ def bubble_sort_recursive[T: Comparable](collection: list[T]) -> list[T]:
143143
length = len(collection)
144144
swapped = False
145145
for i in range(length - 1):
146-
if collection[i] > collection[i + 1]:
146+
if collection[i + 1] < collection[i]:
147147
collection[i], collection[i + 1] = collection[i + 1], collection[i]
148148
swapped = True
149149

0 commit comments

Comments
 (0)