diff --git a/algorithmen/bubblesort.py b/algorithmen/bubblesort.py new file mode 100644 index 0000000..b5c01f2 --- /dev/null +++ b/algorithmen/bubblesort.py @@ -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)