mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-21 21:27:36 +00:00
Co-authored-by: goodm2 <4qjpngu8mem8cz>
This commit is contained in:
parent
6bb9a027bb
commit
81c46dfd55
@ -7,6 +7,7 @@ python3 -m doctest -v quick_sort.py
|
|||||||
For manual testing run:
|
For manual testing run:
|
||||||
python3 quick_sort.py
|
python3 quick_sort.py
|
||||||
"""
|
"""
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
def quick_sort(collection: list) -> list:
|
def quick_sort(collection: list) -> list:
|
||||||
@ -26,8 +27,8 @@ def quick_sort(collection: list) -> list:
|
|||||||
if len(collection) < 2:
|
if len(collection) < 2:
|
||||||
return collection
|
return collection
|
||||||
pivot = collection.pop() # Use the last element as the first pivot
|
pivot = collection.pop() # Use the last element as the first pivot
|
||||||
greater = [] # All elements greater than pivot
|
greater: List[int] = [] # All elements greater than pivot
|
||||||
lesser = [] # All elements less than or equal to pivot
|
lesser: List[int] = [] # All elements less than or equal to pivot
|
||||||
for element in collection:
|
for element in collection:
|
||||||
(greater if element > pivot else lesser).append(element)
|
(greater if element > pivot else lesser).append(element)
|
||||||
return quick_sort(lesser) + [pivot] + quick_sort(greater)
|
return quick_sort(lesser) + [pivot] + quick_sort(greater)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user