[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-10-15 08:33:24 +00:00
parent 7417932ba4
commit 7299b9c866

View File

@ -1,5 +1,6 @@
from __future__ import annotations
def partition(array: list, start: int, end: int) -> int:
"""Helper function for Quick Sort.
@ -22,7 +23,7 @@ def partition(array: list, start: int, end: int) -> int:
>>> array
[]
"""
if not array:
if not array:
return 0
pivot = array[end]
index = start - 1
@ -30,8 +31,9 @@ def partition(array: list, start: int, end: int) -> int:
if array[j] <= pivot:
index += 1
array[index], array[j] = array[j], array[index]
array[index+1], array[end] = array[end], array[index+1]
return index+1
array[index + 1], array[end] = array[end], array[index + 1]
return index + 1
def quicksort(array, start, end):
"""Returns a list of sorted array elements using Quick Sort.
@ -61,9 +63,11 @@ def quicksort(array, start, end):
"""
if start < end:
partition_index = partition(array, start, end)
quicksort(array, start, partition_index-1)
quicksort(array, partition_index+1, end)
quicksort(array, start, partition_index - 1)
quicksort(array, partition_index + 1, end)
if __name__ == "__main__":
import doctest
doctest.testmod()