From 558c1ff1e5f8fe813a8549171b5db4d089450a2f Mon Sep 17 00:00:00 2001 From: karrad1201 Date: Wed, 4 Feb 2026 22:15:40 +0500 Subject: [PATCH] Add type annotations to cycle_sort --- sorts/cycle_sort.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sorts/cycle_sort.py b/sorts/cycle_sort.py index 7177c8ea110d..fd635c6044ba 100644 --- a/sorts/cycle_sort.py +++ b/sorts/cycle_sort.py @@ -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]: """ >>> cycle_sort([4, 3, 2, 1]) [1, 2, 3, 4] @@ -51,3 +54,5 @@ def cycle_sort(array: list) -> list: 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") \ No newline at end of file