From c0c2cad82b3bb298fe8b7a31908322713fb29f19 Mon Sep 17 00:00:00 2001 From: Spectre Date: Mon, 16 Dec 2024 09:54:56 +0100 Subject: [PATCH] quick --- partition_fusion/code2.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 partition_fusion/code2.py diff --git a/partition_fusion/code2.py b/partition_fusion/code2.py new file mode 100644 index 0000000..231a41c --- /dev/null +++ b/partition_fusion/code2.py @@ -0,0 +1,26 @@ +from random import shuffle +i = 0 +def fusion(liste_1,liste_2): + global i + i+=1 + if len(liste_1) == 0: + return liste_2 + if len(liste_2) == 0: + return liste_1 + if liste_1[0] <= liste_2[0]: + return [liste_1[0]] + fusion(liste_1[1:],liste_2) + + return [liste_2[0]] + fusion(liste_1,liste_2[1:]) + +def tri_pf(liste): + if len(liste)<=1: + return liste + millieu = len(liste)//2 + return fusion(tri_pf(liste[:millieu]), tri_pf(liste[millieu:])) + + + +test = [23,8,20,10,13,1] +print(test) +test = tri_pf(test) +print(test, i )