From 96d79c4cae96b0630a4fae32427c6864ddf935d6 Mon Sep 17 00:00:00 2001 From: Martin Putzlocher Date: Mon, 2 May 2022 06:54:54 +0200 Subject: [PATCH] =?UTF-8?q?TrippleSort=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- algorithmen/tripplesort.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 algorithmen/tripplesort.py diff --git a/algorithmen/tripplesort.py b/algorithmen/tripplesort.py new file mode 100644 index 0000000..56c09ee --- /dev/null +++ b/algorithmen/tripplesort.py @@ -0,0 +1,23 @@ +l = [12,124,1,31,51,4563,76,43,532,7,98,786,63,68,2,15,764,345,2,7,85] + + +def tripplesort(unsorted_list, l=None, r=None): + if l is None: + l = 0 + if r is None: + r = len(unsorted_list)-1 + + print("l {}, r {}, list: {}".format(l,r,unsorted_list)) + + if l < r-1: + k = (r-l+1) // 3 + tripplesort(unsorted_list, l, r-k) + tripplesort(unsorted_list, l+k, r) + tripplesort(unsorted_list, l, r-k) + else: + # Vertauschen + if unsorted_list[l] > unsorted_list[r]: + unsorted_list[l], unsorted_list[r] = unsorted_list[r], unsorted_list[l] + +tripplesort(l) +print(l)