Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions code_to_optimize/bubble_sort_codeflash_trace.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from codeflash.benchmarking.codeflash_trace import codeflash_trace


@codeflash_trace
def sorter(arr):
for i in range(len(arr)):
for j in range(len(arr) - 1):
swapped = False
for j in range(len(arr) - 1 - i):
if arr[j] > arr[j + 1]:
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
arr[j], arr[j + 1] = arr[j + 1], arr[j]
swapped = True
if not swapped:
break
return arr


@codeflash_trace
def recursive_bubble_sort(arr, n=None):
# Initialize n if not provided
Expand All @@ -27,10 +32,12 @@ def recursive_bubble_sort(arr, n=None):
# Recursively sort the remaining n-1 elements
return recursive_bubble_sort(arr, n - 1)


class Sorter:
@codeflash_trace
def __init__(self, arr):
self.arr = arr

@codeflash_trace
def sorter(self, multiplier):
for i in range(len(self.arr)):
Expand Down
Loading