Advertisement
arturParchem

[P] QuicSort

Sep 26th, 2022 (edited)
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. t=[0,7,6,0,7,0,2,1]
  2. #Quick Sort
  3. def QuickSort(t:list):
  4.     le = []
  5.     eq = []
  6.     gr = []
  7.     if len(t) > 1:
  8.         pivot = t[0]
  9.         for x in t:
  10.             if x < pivot:
  11.                 le.append(x)
  12.             elif x == pivot:
  13.                 eq.append(x)
  14.             elif x > pivot:
  15.                 gr.append(x)
  16.         return QuickSort(le)+eq+QuickSort(gr)
  17.     else:
  18.         return t
  19. print(QuickSort(t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement