TrippleSort hinzugefügt

master
Martin Putzlocher 2022-05-02 06:54:54 +02:00
parent 003049422f
commit 96d79c4cae
1 changed files with 23 additions and 0 deletions

View File

@ -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)