From d6c861cfc138e3dc3abff7a400e1039cc731d25c Mon Sep 17 00:00:00 2001 From: Aubert Date: Wed, 15 Oct 2025 12:22:36 +0200 Subject: [PATCH] il --- Bail.java | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ Ex3.class | Bin 0 -> 1093 bytes Ex3.java | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Exo2.md | 15 ++++++++++ 4 files changed, 166 insertions(+) create mode 100644 Bail.java create mode 100644 Ex3.class create mode 100644 Ex3.java create mode 100644 Exo2.md diff --git a/Bail.java b/Bail.java new file mode 100644 index 0000000..33dca70 --- /dev/null +++ b/Bail.java @@ -0,0 +1,71 @@ +import java.util.Arrays; +import java.util.Comparator; + +public class Bail { + + public static void main(String[] args) { + // Exemple de tableau à 3 dimensions + Integer[][][] tableau3D = { + { {3, 1, 2}, {9, 0, 8} }, + { {4, 5, 1}, {2, 2, 2} } + }; + + // Appel de la fonction de tri + trierND(tableau3D); + + // Affichage du tableau trié + System.out.println("Tableau trié : "); + System.out.println(Arrays.deepToString(tableau3D)); + } + + /** + * Fonction qui trie un tableau de n'importe quelle dimension. + * Si c'est un tableau d'entiers, on le trie directement. + * Sinon, on trie les sous-tableaux récursivement, puis le tableau actuel + * selon la somme des sous-tableaux. + */ + public static void trierND(Object tableau) { + if (tableau instanceof int[]) { + // Si on est au dernier niveau (tableau d'entiers) + Arrays.sort((int[]) tableau); + } else if (tableau instanceof Object[]) { + Object[] tab = (Object[]) tableau; + + // On trie d'abord les sous-tableaux (appel récursif) + for (Object sousTab : tab) { + trierND(sousTab); + } + + // Puis on trie le tableau courant selon la somme de ses sous-tableaux + Arrays.sort(tab, new Comparator() { + @Override + public int compare(Object a, Object b) { + int sommeA = sommeRecursive(a); + int sommeB = sommeRecursive(b); + return Integer.compare(sommeA, sommeB); + } + }); + } + } + + /** + * Fonction qui calcule récursivement la somme d'un tableau à N dimensions. + */ + public static int sommeRecursive(Object tableau) { + if (tableau instanceof int[]) { + int somme = 0; + for (int valeur : (int[]) tableau) { + somme += valeur; + } + return somme; + } else if (tableau instanceof Object[]) { + int sommeTotale = 0; + for (Object sousTab : (Object[]) tableau) { + sommeTotale += sommeRecursive(sousTab); + } + return sommeTotale; + } else { + return 0; + } + } +} diff --git a/Ex3.class b/Ex3.class new file mode 100644 index 0000000000000000000000000000000000000000..b123b3cdcf269744f32c7a5b04ab774f2b3ce45d GIT binary patch literal 1093 zcmX^0Z`VEs1_pBm6D|gB25Bw^E(RHP23bx9IR<$S1_dq#MFu4<24w~nkc=t^gBm-7 zIy-{~BLkaFW?p8A9U}v?hGrNe1B-KhN-84*zfWdfs$XetQfg61Vp2{jBLi1bX;M;7 zYH@y12_plmMzkkLHE(c9Vsf@`VgXbUOG#>R2_plWMl?j8B{wlMkC8!4Bibh`u`E$P zCowNwKe(hQGcVm*GmM=1eX-0Cgxf*G6;jsM-^sdU@rhE%E@D75Y>QaL=6R)MWrQ~Ir@%8 zMTwQgj0_wl`H)}&2cD-UrbY%u22e~hFfcH%Fff9`ih+@VkAZ=UrUrl#-GKeg@tkX|4Y)d{+|Td!34HLkAa(kfq|2OnSqCam4TOm zkAa^-nn933i9v`#he4RZkU@mOn1PqUl0lromO+9+h=GAYih<=H12Y2yr78d_VRyO}&pG^!bLaf^u z*tC6h_SrE*Ls3dcl*P!3brS=NB(vXhCz$L zg+ZGkf array[i]) + { + valeur = array[i-1]; + array[i-1] = array[i]; + array[i] = valeur; + swapped=true; + } + } + } while(swapped); + } + + + + public static void test(List tab,int profondeur){ + for (int i=0;i somme(tab[i])) { + tmp = tab[i - 1]; + tab[i - 1] = tab[i]; + tab[i] = tmp; + swapped = true; + } + } + } while (swapped); + } + + + + public static void main(String[] args) { + int[][] tableau = { + {0, 3, 2}, + {9, 4, 5}, + {4, 1, 3} + }; + + System.out.println("Avant tri :"); + for (int[] ligne : tableau) { + System.out.println(Arrays.toString(ligne)); + } + + // Appel du tri + test(tableau); + + System.out.println("\nAprès tri :"); + for (int[] ligne : tableau) { + System.out.println(Arrays.toString(ligne)); + } + } + +} \ No newline at end of file diff --git a/Exo2.md b/Exo2.md new file mode 100644 index 0000000..100dbc5 --- /dev/null +++ b/Exo2.md @@ -0,0 +1,15 @@ +Marvin Lebreton et Maxime AUbert + +# Ex2 + +## 1: + +La réponse est o(n*m) car y'a un tableau imbriqué dans un autre tableau + +## 2: + +La réponse est o(n) parce que le nombre d'itération de la boucle dépend de la val de n + +## 3: + +La réponse est o(1), peu importe la val de x, on va toujours toujours au max faire 3 instruction \ No newline at end of file