Skip to content

Commit d23cc7c

Browse files
Your GitHub UsernameYour GitHub Username
authored andcommitted
fix: improve output readability in bubble_sort.py
1 parent a71618f commit d23cc7c

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

sorts/bubble_sort.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,24 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
119119
timer_iterative = timeit(
120120
"bubble_sort_iterative(unsorted[:])", globals=globals(), number=num_runs
121121
)
122-
print("\nIterative bubble sort:")
123-
print(*bubble_sort_iterative(unsorted), sep=",")
124-
print(f"Processing time (iterative): {timer_iterative:.5f}s for {num_runs:,} runs")
122+
123+
print(f"Total runs for benchmark: {num_runs:,}\n")
124+
125+
# Iterative version
126+
print("➡️ Iterative Bubble Sort:")
127+
sorted_iter = bubble_sort_iterative(unsorted)
128+
print("Sorted Output:", ", ".join(map(str, sorted_iter)))
129+
print(f"Time Taken (Iterative): {timer_iterative:.5f}s\n")
130+
131+
# Recursive version
132+
unsorted = sample(range(-50, 50), 100)
133+
timer_recursive = timeit(
134+
"bubble_sort_recursive(unsorted[:])", globals=globals(), number=num_runs
135+
)
136+
print("➡️ Recursive Bubble Sort:")
137+
sorted_rec = bubble_sort_recursive(unsorted)
138+
print("Sorted Output:", ", ".join(map(str, sorted_rec)))
139+
print(f"Time Taken (Recursive): {timer_recursive:.5f}s")
140+
141+
print("\n✅ Comparison completed successfully!")
125142

126-
unsorted = sample(range(-50, 50), 100)
127-
timer_recursive = timeit(
128-
"bubble_sort_recursive(unsorted[:])", globals=globals(), number=num_runs
129-
)
130-
print("\nRecursive bubble sort:")
131-
print(*bubble_sort_recursive(unsorted), sep=",")
132-
print(f"Processing time (recursive): {timer_recursive:.5f}s for {num_runs:,} runs")

0 commit comments

Comments
 (0)