From 62e51fe48753a93a6c38834fd0b22eda1941644f Mon Sep 17 00:00:00 2001 From: Metehan Date: Thu, 31 Oct 2019 21:49:25 +0300 Subject: [PATCH] recursive quick sort (#1536) * recursive quick sort * recursive quick sort * Delete recursive-quick-sort * Update recursive-quick-sort.py --- sorts/recursive-quick-sort.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 sorts/recursive-quick-sort.py diff --git a/sorts/recursive-quick-sort.py b/sorts/recursive-quick-sort.py new file mode 100644 index 000000000..c28a14e37 --- /dev/null +++ b/sorts/recursive-quick-sort.py @@ -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()