We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 69d4b7d commit 41dbd32Copy full SHA for 41dbd32
algorithms/sort/bubble_sort.py
@@ -4,19 +4,29 @@
4
5
Worst-case performance: O(N^2)
6
7
+If you call bubble_sort(arr,True), you can see the process of the sort
8
+Default is simulation = False
9
+
10
"""
11
12
-def bubble_sort(arr):
13
+def bubble_sort(arr, simulation=False):
14
def swap(i, j):
15
arr[i], arr[j] = arr[j], arr[i]
16
17
n = len(arr)
18
swapped = True
19
20
+ if simulation:
21
+ print(arr)
22
23
while swapped:
24
swapped = False
25
for i in range(1, n):
26
if arr[i - 1] > arr[i]:
27
swap(i - 1, i)
28
29
30
31
32
return arr
0 commit comments