mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +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
e9779a2e45
commit
06fcd146bf
|
@ -9,6 +9,7 @@ For manual testing run:
|
||||||
python cyclic_sort.py
|
python cyclic_sort.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def cyclic_sort(nums: list) -> list:
|
def cyclic_sort(nums: list) -> list:
|
||||||
"""
|
"""
|
||||||
Sorts the input list in-place using the Cyclic Sort algorithm.
|
Sorts the input list in-place using the Cyclic Sort algorithm.
|
||||||
|
@ -32,7 +33,7 @@ def cyclic_sort(nums: list) -> list:
|
||||||
while i < len(nums):
|
while i < len(nums):
|
||||||
# Calculate the correct index for the current element
|
# Calculate the correct index for the current element
|
||||||
correct_index = nums[i] - 1
|
correct_index = nums[i] - 1
|
||||||
|
|
||||||
# If the current element is not at its correct position,
|
# If the current element is not at its correct position,
|
||||||
# swap it with the element at its correct index
|
# swap it with the element at its correct index
|
||||||
if nums[i] != nums[correct_index]:
|
if nums[i] != nums[correct_index]:
|
||||||
|
@ -44,6 +45,7 @@ def cyclic_sort(nums: list) -> list:
|
||||||
|
|
||||||
return nums
|
return nums
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user