Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sorts/cycle_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
Source: https://en.wikipedia.org/wiki/Cycle_sort
"""

from typing import TypeVar

def cycle_sort(array: list) -> list:
T = TypeVar('T', int, float)

def cycle_sort(array: list[T]) -> list[T]:

Check failure on line 10 in sorts/cycle_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (UP047)

sorts/cycle_sort.py:10:5: UP047 Generic function `cycle_sort` should use type parameters
"""
>>> cycle_sort([4, 3, 2, 1])
[1, 2, 3, 4]
Expand Down Expand Up @@ -51,3 +54,5 @@
if __name__ == "__main__":
assert cycle_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
assert cycle_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]
assert cycle_sort([-.1, -.2, 1.3, -.8]) == [-0.8, -0.2, -0.1, 1.3]
print("All tests passed")

Check failure on line 58 in sorts/cycle_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W292)

sorts/cycle_sort.py:58:30: W292 No newline at end of file
Loading