From 20915f1b9a1314d74255a4d254aa693bcbed5b16 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sun, 27 Sep 2026 17:11:34 +0530 Subject: [PATCH] fix: make bubble sort work with comparable items --- sorts/bubble_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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