Skip to content

Commit a391364

Browse files
committed
Add a bubble sort example
1 parent 1ed71a1 commit a391364

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def bubble_sort_list(a_list):
2+
n = len(a_list)
3+
for i in range(n):
4+
is_sorted = True
5+
for j in range(n - i - 1):
6+
if a_list[j] > a_list[j + 1]:
7+
a_list[j], a_list[j + 1] = a_list[j + 1], a_list[j]
8+
is_sorted = False
9+
if is_sorted:
10+
break
11+
return a_list

0 commit comments

Comments
 (0)