diff --git a/codeflash/bubble_sort.py b/codeflash/bubble_sort.py new file mode 100644 index 000000000..abc44b353 --- /dev/null +++ b/codeflash/bubble_sort.py @@ -0,0 +1,15 @@ +from typing import List, Union + + +def sorter(arr: Union[List[int], List[float]]) -> Union[List[int], List[float]]: + for i in range(len(arr)): + swapped = False + for j in range(len(arr) - i - 1): + if arr[j] > arr[j + 1]: + temp = arr[j] + arr[j] = arr[j + 1] + arr[j + 1] = temp + swapped = True + if not swapped: + break + return arr