diff --git a/exo3$1.class b/exo3$1.class new file mode 100644 index 0000000..ab8e4f6 Binary files /dev/null and b/exo3$1.class differ diff --git a/exo3.class b/exo3.class new file mode 100644 index 0000000..6b0d7cd Binary files /dev/null and b/exo3.class differ diff --git a/exo3.java b/exo3.java new file mode 100644 index 0000000..48771a7 --- /dev/null +++ b/exo3.java @@ -0,0 +1,52 @@ +import java.util.Arrays; + +public class exo3 { + private static int calculSomme(int[] ligne) { + int somme = 0; + for (int element : ligne) { + somme += element; + } + return somme; + } + + public static int[][] trierTab(int[][] tab) { + Arrays.sort(tab, (val1, val2) -> Integer.compare(calculSomme(val1), calculSomme(val2))); + + for (int[] val : tab) { + Arrays.sort(val); + } + + return tab; + } + + public static void main(String[] args) { + int[][] orginalTab = { + {0, 3, 2}, + {9, 4, 5}, + {4, 1, 3}, + }; + // int[][] orginalTab = { + // {7, 2, 9, 1}, + // {3, 8, 4}, + // {6, 1, 5, 2, 3}, + // {2, 9}, + // {4, 7, 1, 8}, + // }; + + afficherTab(orginalTab); + System.out.println("-----"); + + int[][] resultTab = trierTab(orginalTab); + + afficherTab(resultTab); + } + + private static void afficherTab(int[][] tab) { + for (int i = 0; i < tab.length; i++) { + for (int j = 0; j < tab[i].length; j++) { + System.out.print(tab[i][j] + " "); + } + System.out.println(); + } + } +} \ No newline at end of file diff --git a/exo3.pdf b/exo3.pdf new file mode 100644 index 0000000..1c06412 --- /dev/null +++ b/exo3.pdf @@ -0,0 +1,5 @@ +Complexité algorithmique de la fonction trierTab: +Ici il y a deux principales instructions qu'on va calculer, le tri par somme et le tri de chaque sous-tableau +Le tri O(N * M Log N) +Le tri de chaque sous tableau O(N * M Log M) +Donc le calcul total correspond à l'addition des deux : O(N * M Log N) + O(N * M Log M) \ No newline at end of file