Skip to content
Snippets Groups Projects
Commit 31c6e633 authored by Louis Chmielewski's avatar Louis Chmielewski
Browse files

merge_sort is_sorted

parent acd8c43a
No related branches found
No related tags found
No related merge requests found
...@@ -125,7 +125,24 @@ def is_sorted(l: ApLst, comp: Callable[[T, T], int]=compare) -> bool: ...@@ -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])) $$$ is_sorted(native_to_list([1, 2, 4, 3]))
False 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]: def split(l: ApLst) -> tuple[ApLst, ApLst]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment