Bubblesort added

master
Martin Putzlocher 2022-04-26 23:22:21 +02:00
parent cbe6432e1f
commit 003049422f
1 changed files with 20 additions and 0 deletions

20
algorithmen/bubblesort.py Normal file
View File

@ -0,0 +1,20 @@
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)