Skip to content

Commit bb44b78

Browse files
authored
feat: add bubble sort in Python (doocs#812)
1 parent 1f93c2d commit bb44b78

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def bubbleSort(arr):
2+
n = len(arr)
3+
# Iterate over all array elements
4+
for i in range(n):
5+
# Last i elements are already in place
6+
for j in range(n - i - 1):
7+
if arr[j] > arr[j + 1]:
8+
arr[j], arr[j + 1] = arr[j + 1], arr[j]
9+
10+
11+
arr = [64, 34, 25, 12, 22, 11, 90]
12+
bubbleSort(arr)
13+
print(arr)

0 commit comments

Comments
 (0)