From 503f893e4c4f806e2be825b1c07baa6fc2d53122 Mon Sep 17 00:00:00 2001
From: Dariya Kinadinova <dariya.kinadinova.etu@univ-lille.fr>
Date: Wed, 10 Apr 2024 10:17:32 +0200
Subject: [PATCH] split

---
 tp9/merge_sort.py | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/tp9/merge_sort.py b/tp9/merge_sort.py
index 4da1083..44bed10 100644
--- a/tp9/merge_sort.py
+++ b/tp9/merge_sort.py
@@ -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
-- 
GitLab