Skip to content

Commit ec90d70

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7ce48ed commit ec90d70

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

divide_and_conquer/quicksort.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ def quicksort(arr: list) -> list:
22
"""Quicksort function implementation in Python.
33
44
https://en.wikipedia.org/wiki/Quicksort
5-
5+
66
>>> quicksort([])
77
[]
8-
8+
99
>>> quicksort([5])
1010
[5]
11-
11+
1212
>>> quicksort([3, 6, 8, 10, 1, 2, 1, 3, 2, 8])
1313
[1, 1, 2, 2, 3, 3, 6, 8, 8, 10]
1414
"""
15-
15+
1616
# If the length of the array is less than or equal to 1, then there's nothing to sort, so return the given array
1717
if len(arr) <= 1:
1818
return arr
19-
19+
2020
# In quicksort a element needs to be selected as pivot, it can be anywhere
2121
# In this case let the pivot be the first element
22-
pivot = arr[0]
22+
pivot = arr[0]
2323

2424
# Using list comprehension creating three list object: smaller_elemnts, pivot_elements & larger_elements based on the comparison with the pivot element
2525
smaller_elements = [x for x in arr if x < pivot]
@@ -29,6 +29,8 @@ def quicksort(arr: list) -> list:
2929
# Recursively splitting the list object to determine the correct position of the element
3030
return quicksort(smaller_elements) + pivot_elements + quicksort(larger_elements)
3131

32+
3233
if __name__ == "__main__":
3334
import doctest
35+
3436
doctest.testmod()

0 commit comments

Comments
 (0)