Informatik10/algorithmen/tripplesort.py

24 lines
625 B
Python

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)