From 7299b9c866faa6b25c6ffe4239fcca2430d3a884 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 08:33:24 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- divide_and_conquer/quicksort.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/divide_and_conquer/quicksort.py b/divide_and_conquer/quicksort.py index d40a905a2..87ccad4c9 100644 --- a/divide_and_conquer/quicksort.py +++ b/divide_and_conquer/quicksort.py @@ -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()