-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.py
More file actions
36 lines (26 loc) · 891 Bytes
/
Copy pathbubble.py
File metadata and controls
36 lines (26 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def bubble_sort(unordered_list):
iteration_number = len(unordered_list) - 1
for i in range(iteration_number):
for j in range(iteration_number):
if unordered_list[j] > unordered_list[j+1]:
temp = unordered_list[j]
unordered_list[j] = unordered_list[j+1]
unordered_list[j+1] = temp
def main():
unordered_list = [5, 2]
i = 0
first_element = unordered_list[0]
second_element = unordered_list[1]
temp = unordered_list[0]
unordered_list[0] = unordered_list[1]
unordered_list[1] = temp
print(unordered_list)
"""########################################################################################"""
my_list = [4,3,2,1]
bubble_sort(my_list)
print(my_list)
my_list = [1,2,3,4]
bubble_sort(my_list)
print(my_list)
if __name__ == "__main__":
main()