You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to this question on StackOverflow it is better to use the median or a random value as a pivot.
Currently the implementation uses the last element as the pivot.
defquick_sort(collection: list) ->list:
iflen(collection) <2:
returncollectionpivot=collection.pop() # <-- Use the last element as the first pivotgreater: list[int] = []
lesser: list[int] = []
forelementincollection:
(greaterifelement>pivotelselesser).append(element)
returnquick_sort(lesser) + [pivot] +quick_sort(greater)