Informatik10/algorithmen/bubblesort.py

21 lines
575 B
Python
Raw Normal View History

2022-04-26 21:22:21 +00:00
l = [12,124,1,31,51,4563,76,43,532,7,98,786,63,68,2,15,764,345,2,7,85]
def bubblesort(unsorted_list):
number_of_elements = len(unsorted_list)
swapped = True
for j in range(number_of_elements-1):
for i in range(number_of_elements-1-j):
if unsorted_list[i] > unsorted_list[i+1]:
tmp = unsorted_list[i+1]
unsorted_list[i+1] = unsorted_list[i]
unsorted_list[i] = tmp
print(unsorted_list)
sorted_list = unsorted_list
return sorted_list
bubblesort(l)