1
This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
Project_Steam_Tracker/sorting.py

59 lines
1.6 KiB
Python

def nest_qsort(tpl, colnum, reverse=False):
"""deze functie sorteert de geneste tuple zoals beschreven in de README.md"""
small = []
same = []
large = []
if len(tpl) > 1:
pivot = tpl[0][colnum]
if reverse:
for x in tpl:
if x[colnum] > pivot:
small.append(x)
elif x[colnum] == pivot:
same.append(x)
elif x[colnum] < pivot:
large.append(x)
else:
for x in tpl:
if x[colnum] < pivot:
small.append(x)
elif x[colnum] == pivot:
same.append(x)
elif x[colnum] > pivot:
large.append(x)
return nest_qsort(small, colnum, reverse) + same + nest_qsort(large, colnum, reverse)
else:
return tpl
def qsort(tpl, reverse=False):
"""Deze functie kan een lijst of tuple met waardes sorteren"""
small = []
same = []
large = []
if len(tpl) > 1:
pivot = tpl[0]
if reverse:
for x in tpl:
if x > pivot:
small.append(x)
elif x == pivot:
same.append(x)
elif x < pivot:
large.append(x)
else:
for x in tpl:
if x < pivot:
small.append(x)
elif x == pivot:
same.append(x)
elif x > pivot:
large.append(x)
return qsort(small, reverse) + same + qsort(large, reverse)
else:
return tpl