From 52ad9376fe71619598d4a73dc51825aaaafe167e Mon Sep 17 00:00:00 2001 From: Martin Putzlocher Date: Mon, 2 May 2022 07:00:51 +0200 Subject: [PATCH] Added selectionsort --- algorithmen/selectionsort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 algorithmen/selectionsort.py diff --git a/algorithmen/selectionsort.py b/algorithmen/selectionsort.py new file mode 100644 index 0000000..9a19da0 --- /dev/null +++ b/algorithmen/selectionsort.py @@ -0,0 +1,15 @@ +l = [12,124,1,31,51,4563,76,43,532,7,98,786,63,68,2,15,764,345,2,7,85] + +def selectionsort(alist): + blist = alist[:] # work on a copy + result = list() + for i in range(len(blist)): + # find min element + min_e = min(blist) + result.append(min_e) + blist.remove(min_e) + print(result) + return result + +sorted = selectionsort(l) +print(sorted)