Skip to content

Commit 62e51fe

Browse files
metehaansevercclauss
authored andcommitted
recursive quick sort (TheAlgorithms#1536)
* recursive quick sort * recursive quick sort * Delete recursive-quick-sort * Update recursive-quick-sort.py
1 parent c717f8d commit 62e51fe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: sorts/recursive-quick-sort.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def quick_sort(data: list) -> list:
2+
"""
3+
>>> for data in ([2, 1, 0], [2.2, 1.1, 0], "quick_sort"):
4+
... quick_sort(data) == sorted(data)
5+
True
6+
True
7+
True
8+
"""
9+
if len(data) <= 1:
10+
return data
11+
else:
12+
return (
13+
quick_sort([e for e in data[1:] if e <= data[0]])
14+
+ [data[0]]
15+
+ quick_sort([e for e in data[1:] if e > data[0]])
16+
)
17+
18+
19+
if __name__ == "__main__":
20+
import doctest
21+
22+
doctest.testmod()

0 commit comments

Comments
 (0)