diff --git a/Tp09/merge_sort.py b/Tp09/merge_sort.py index 0c016e04574e488243f6f949e12cd3c0091b40a2..91b5736c021d32db3c3193cb60b0c419c0689ca7 100755 --- a/Tp09/merge_sort.py +++ b/Tp09/merge_sort.py @@ -125,7 +125,24 @@ def is_sorted(l: ApLst, comp: Callable[[T, T], int]=compare) -> bool: $$$ is_sorted(native_to_list([1, 2, 4, 3])) False """ - ... + if l.is_empty(): + return True + + current = l.head() + rest = l.tail() + + while not rest.is_empty(): + next_element = rest.head() + if comp(current, next_element) > 0: + return False + current = next_element + rest = rest.tail() + + return True +# compteur = 0 +# while not l.is_empty and l.comp(l.head(), is_sorted(l.tail()) == -1): +# compteur = compteur + 1 +# return compteur == length(l) def split(l: ApLst) -> tuple[ApLst, ApLst]: