mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-08 14:55:53 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
7417932ba4
commit
7299b9c866
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
def partition(array: list, start: int, end: int) -> int:
|
def partition(array: list, start: int, end: int) -> int:
|
||||||
"""Helper function for Quick Sort.
|
"""Helper function for Quick Sort.
|
||||||
|
|
||||||
@ -30,8 +31,9 @@ def partition(array: list, start: int, end: int) -> int:
|
|||||||
if array[j] <= pivot:
|
if array[j] <= pivot:
|
||||||
index += 1
|
index += 1
|
||||||
array[index], array[j] = array[j], array[index]
|
array[index], array[j] = array[j], array[index]
|
||||||
array[index+1], array[end] = array[end], array[index+1]
|
array[index + 1], array[end] = array[end], array[index + 1]
|
||||||
return index+1
|
return index + 1
|
||||||
|
|
||||||
|
|
||||||
def quicksort(array, start, end):
|
def quicksort(array, start, end):
|
||||||
"""Returns a list of sorted array elements using Quick Sort.
|
"""Returns a list of sorted array elements using Quick Sort.
|
||||||
@ -61,9 +63,11 @@ def quicksort(array, start, end):
|
|||||||
"""
|
"""
|
||||||
if start < end:
|
if start < end:
|
||||||
partition_index = partition(array, start, end)
|
partition_index = partition(array, start, end)
|
||||||
quicksort(array, start, partition_index-1)
|
quicksort(array, start, partition_index - 1)
|
||||||
quicksort(array, partition_index+1, end)
|
quicksort(array, partition_index + 1, end)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user