diff --git a/.classpath b/.classpath index d3688f0..c0b4a16 100644 --- a/.classpath +++ b/.classpath @@ -7,10 +7,6 @@ - - - - - + diff --git a/Enoncés/TP/TP2_Tri.pdf b/Enoncés/TP/TP2_Tri.pdf new file mode 100644 index 0000000..ff9b7c1 Binary files /dev/null and b/Enoncés/TP/TP2_Tri.pdf differ diff --git a/src/TP2/demoTris.java b/src/TP2/demoTris.java new file mode 100644 index 0000000..ffac5be --- /dev/null +++ b/src/TP2/demoTris.java @@ -0,0 +1,68 @@ +package TP2; + +import java.util.Arrays; + +public class demoTris { + + int[] tabA = new int[8]; + tabA[0] = 8; + tabA[1] = 4; + tabA[2] = 25; + tabA[3] = 28; + tabA[4] = 13; + tabA[5] = 40; + tabA[6] = 30; + tabA[7] = 23; + + public static void triFusion(int[] numbers) { + mergeSort(numbers, 0, numbers.length); + } + + private static void mergeSort(int[] tab, int min, int max) { + int mid = 0; + if(min != max) { + mid = (min+max)/2; + + mergeSort(tab, min, mid); + mergeSort(tab, mid+1, max); + + int[] tmpTab = new int[max-min+1]; + int[] t1 = Arrays.copyOfRange(tab, min, mid+1); + int[] t2 = Arrays.copyOfRange(tab, mid+1, max); + + Fusion(t1, t2, tmpTab); + + for(int i=0; i < max-min; i++) { + tab[min+i] = tmpTab[i]; + } + } + } + + private static void Fusion(int[] tab1, int[] tab2, int[] tab) { + int i = 0; int i1 = 0; int i2 = 0; + + while(i1 < tab1.length && i2 < tab2.length) { + if(tab1[i1] < tab2[i2]) { + tab[i] = tab1[i1]; + i++;i1++; + } else { + tab[i] = tab2[i2]; + i++;i2++; + } + } + + while(i1 + * + * @author Dr. Denis Pallez
+ * http://denispallez.i3s.unice.fr + */ + +public class TrisTestEtudiant { + // array containing values to be sorted + protected static int[] nombres; + // size of the array to be sorted + protected static final int SIZE = 10; + // array will contain values in [1, MAX_VALUE] + protected static final int MAX_VALUE = 10; + + // Random number generator + static Random generator ; + + /** check whether array numbers is correctly sorted or not */ + protected boolean arraySorted(int[] numbers) { + for (int i = 0; i < numbers.length - 1; i++) { + if (numbers[i] > numbers[i + 1]) { + return false; + } + } + return true; + } + + /** initialize an array with random values*/ + protected void initRandom() { + for (int i = 0; i < nombres.length; i++) { + nombres[i] = generator.nextInt(MAX_VALUE); + } + } + + /** create an array sorted in the decreasing order*/ + protected void initWorst() { + for (int i = 0; i < nombres.length; i++) { + nombres[i] = MAX_VALUE-i; + } + } + + /** init an array with values already sorted*/ + protected void initBest() { + for (int i = 0; i < nombres.length; i++) { + nombres[i] = i; + } + } + + /** initialize an array with random values that could appear several times*/ + protected void initSameValues() { + final int NBVAL_DIFF = nombres.length/2 ; + int[] values = new int[NBVAL_DIFF]; + for (int i=0;i