We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e9779a2 commit 06fcd14Copy full SHA for 06fcd14
sorts/cyclic_sort.py
@@ -9,6 +9,7 @@
9
python cyclic_sort.py
10
"""
11
12
+
13
def cyclic_sort(nums: list) -> list:
14
15
Sorts the input list in-place using the Cyclic Sort algorithm.
@@ -32,7 +33,7 @@ def cyclic_sort(nums: list) -> list:
32
33
while i < len(nums):
34
# Calculate the correct index for the current element
35
correct_index = nums[i] - 1
-
36
37
# If the current element is not at its correct position,
38
# swap it with the element at its correct index
39
if nums[i] != nums[correct_index]:
@@ -44,6 +45,7 @@ def cyclic_sort(nums: list) -> list:
44
45
46
return nums
47
48
49
if __name__ == "__main__":
50
import doctest
51
0 commit comments