From c4a811c6d35946786d670e8539f39a0733ab3335 Mon Sep 17 00:00:00 2001 From: "omkarghodekar140803@gmail.com" Date: Wed, 22 Oct 2025 23:40:02 +0530 Subject: [PATCH] Bubble sort implementation, all test cases pass --- sort.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sort.py b/sort.py index 402e60c..0428bef 100644 --- a/sort.py +++ b/sort.py @@ -50,7 +50,20 @@ def bubble(data: List[Any], comparator: Callable[[Any, Any], bool]) -> List[Any] Returns: List[Any]: A new sorted list. """ - pass + arr = data.copy() # Do not modify original list + n = len(arr) + + for i in range(n): + swapped = False + for j in range(0, n - i - 1): + # If elements are out of order per comparator, swap + if not comparator(arr[j], arr[j + 1]): + arr[j], arr[j + 1] = arr[j + 1], arr[j] + swapped = True + # Optimization: stop if already sorted + if not swapped: + break + return arr @staticmethod def sort(data: List[Any], comparator: Callable[[Any, Any], bool], method: str = "merge") -> List[Any]: