Skip to content

Commit 8f6effe

Browse files
committed
Create bubblesort.py
1 parent d8a3ed9 commit 8f6effe

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bubblesort.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from generator import Generator
2+
3+
4+
def BubbleSort(arr: list) -> list:
5+
n = len(arr)
6+
7+
for i in range(n):
8+
# Last i elements are already in place
9+
for j in range(n - i - 1):
10+
# Swap if the element found is greater than the next element
11+
if arr[j] > arr[j + 1]:
12+
arr[j], arr[j + 1] = arr[j + 1], arr[j]
13+
14+
return arr
15+
16+
17+
if __name__ == '__main__':
18+
arr = Generator(1000)
19+
sorted_list = BubbleSort(arr)
20+
print(sorted_list)

0 commit comments

Comments
 (0)