TrippleSort hinzugefügt
This commit is contained in:
parent
003049422f
commit
96d79c4cae
23
algorithmen/tripplesort.py
Normal file
23
algorithmen/tripplesort.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user