mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
recursive quick sort (#1536)
* recursive quick sort * recursive quick sort * Delete recursive-quick-sort * Update recursive-quick-sort.py
This commit is contained in:
parent
c717f8d860
commit
62e51fe487
22
sorts/recursive-quick-sort.py
Normal file
22
sorts/recursive-quick-sort.py
Normal file
@ -0,0 +1,22 @@
|
||||
def quick_sort(data: list) -> list:
|
||||
"""
|
||||
>>> for data in ([2, 1, 0], [2.2, 1.1, 0], "quick_sort"):
|
||||
... quick_sort(data) == sorted(data)
|
||||
True
|
||||
True
|
||||
True
|
||||
"""
|
||||
if len(data) <= 1:
|
||||
return data
|
||||
else:
|
||||
return (
|
||||
quick_sort([e for e in data[1:] if e <= data[0]])
|
||||
+ [data[0]]
|
||||
+ quick_sort([e for e in data[1:] if e > data[0]])
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
Loading…
Reference in New Issue
Block a user