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.

28 lines
788 B
Python
Raw Normal View History

def qsort(tpl, colnum, reverse=False):
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 qsort(small, colnum, reverse) + same + qsort(large, colnum, reverse)
else:
return tpl