Skip to content

Commit c3f47d4

Browse files
committed
BubbleSort.py finally approved
1 parent 9222b6c commit c3f47d4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#Buuble Sort
2+
3+
def bubble_sort(unordered_list):
4+
iteration_number = len(unordered_list) - 1
5+
for i in range(iteration_number, 0, -1):
6+
for j in range(i):
7+
if unordered_list [j] > unordered_list[j + 1]:
8+
temp = unordered_list[j]
9+
unordered_list[j] = unordered_list[j + 1]
10+
unordered_list[j + 1] = temp
11+
12+
13+
print("-----Bubble Sort Outputs-----\n")
14+
my_list = [4,3,2,1]
15+
bubble_sort(my_list)
16+
print(my_list, '\n')
17+
18+
my_list = [1,12,3,4]
19+
bubble_sort(my_list)
20+
print(my_list)
21+
22+

0 commit comments

Comments
 (0)