Skip to content
Snippets Groups Projects
Commit 503f893e authored by Dariya Kinadinova's avatar Dariya Kinadinova
Browse files

split

parent 2ecacb0c
Branches
No related tags found
No related merge requests found
......@@ -129,7 +129,7 @@ def is_sorted(l: ApLst, comp: Callable[[T, T], int]=compare) -> bool:
for i in range(length(l)-1):
a = l.head()
l = l.tail()
if a > l.head():
if compare(a, l.head()) == 1:
res = False
return res
......@@ -150,7 +150,23 @@ def split(l: ApLst) -> tuple[ApLst, ApLst]:
$$$ all(k in l for k in l3)
True
"""
if not l.is_empty():
liste = list_to_native(l)
if length(l)%2 == 0:
l1 = ApLst()
for i in range(1, (length(l)//2)+1):
l1 = ApLst(liste[-(length(l)//2)-i], l1)
else:
l1 = ApLst()
for i in range(1, (length(l)//2)+2):
l1 = ApLst(liste[-(length(l)//2)-i], l1)
l2 = ApLst()
for i in range(1, (length(l)//2)+1):
l2 = ApLst(liste[-i], l2)
return (l1, l2)
else:
return ()
def merge(l1: ApLst, l2: ApLst,
......@@ -165,7 +181,7 @@ def merge(l1: ApLst, l2: ApLst,
$$$ list_to_native(merge(native_to_list([1, 3, 4, 9]), native_to_list([1, 2, 5])))
[1, 1, 2, 3, 4, 5, 9]
"""
...
def mergesort(l: ApLst, comp: Callable[[T, T], int]=compare) -> ApLst:
......@@ -191,7 +207,4 @@ def mergesort(l: ApLst, comp: Callable[[T, T], int]=compare) -> ApLst:
if (__name__ == '__main__'):
import apl1test
apl1test.testmod("merge_sort.py")
apl1test.testmod("merge_sort.py")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment