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)