28 lines
788 B
Python
28 lines
788 B
Python
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
|