From 003049422f44931f84f5cf1280a7429ec49c1657 Mon Sep 17 00:00:00 2001 From: Martin Putzlocher Date: Tue, 26 Apr 2022 23:22:21 +0200 Subject: [PATCH] Bubblesort added --- algorithmen/bubblesort.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 algorithmen/bubblesort.py 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)